2 * Copyright © 2006-2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
27 #include <linux/dmi.h>
28 #include <linux/module.h>
29 #include <linux/input.h>
30 #include <linux/i2c.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/vgaarb.h>
34 #include <drm/drm_edid.h>
36 #include "intel_drv.h"
37 #include <drm/i915_drm.h>
39 #include "i915_trace.h"
40 #include <drm/drm_atomic.h>
41 #include <drm/drm_atomic_helper.h>
42 #include <drm/drm_dp_helper.h>
43 #include <drm/drm_crtc_helper.h>
44 #include <drm/drm_plane_helper.h>
45 #include <drm/drm_rect.h>
46 #include <linux/dma_remapping.h>
48 /* Primary plane formats for gen <= 3 */
49 static const uint32_t i8xx_primary_formats[] = {
56 /* Primary plane formats for gen >= 4 */
57 static const uint32_t i965_primary_formats[] = {
62 DRM_FORMAT_XRGB2101010,
63 DRM_FORMAT_XBGR2101010,
66 static const uint32_t skl_primary_formats[] = {
73 DRM_FORMAT_XRGB2101010,
74 DRM_FORMAT_XBGR2101010,
78 static const uint32_t intel_cursor_formats[] = {
82 static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
84 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
85 struct intel_crtc_state *pipe_config);
86 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
87 struct intel_crtc_state *pipe_config);
89 static int intel_set_mode(struct drm_atomic_state *state);
90 static int intel_framebuffer_init(struct drm_device *dev,
91 struct intel_framebuffer *ifb,
92 struct drm_mode_fb_cmd2 *mode_cmd,
93 struct drm_i915_gem_object *obj);
94 static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc);
95 static void intel_set_pipe_timings(struct intel_crtc *intel_crtc);
96 static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
97 struct intel_link_m_n *m_n,
98 struct intel_link_m_n *m2_n2);
99 static void ironlake_set_pipeconf(struct drm_crtc *crtc);
100 static void haswell_set_pipeconf(struct drm_crtc *crtc);
101 static void intel_set_pipe_csc(struct drm_crtc *crtc);
102 static void vlv_prepare_pll(struct intel_crtc *crtc,
103 const struct intel_crtc_state *pipe_config);
104 static void chv_prepare_pll(struct intel_crtc *crtc,
105 const struct intel_crtc_state *pipe_config);
106 static void intel_begin_crtc_commit(struct drm_crtc *crtc);
107 static void intel_finish_crtc_commit(struct drm_crtc *crtc);
108 static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc,
109 struct intel_crtc_state *crtc_state);
110 static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state,
112 static void intel_modeset_setup_hw_state(struct drm_device *dev);
114 static struct intel_encoder *intel_find_encoder(struct intel_connector *connector, int pipe)
116 if (!connector->mst_port)
117 return connector->encoder;
119 return &connector->mst_port->mst_encoders[pipe]->base;
128 int p2_slow, p2_fast;
131 typedef struct intel_limit intel_limit_t;
133 intel_range_t dot, vco, n, m, m1, m2, p, p1;
138 intel_pch_rawclk(struct drm_device *dev)
140 struct drm_i915_private *dev_priv = dev->dev_private;
142 WARN_ON(!HAS_PCH_SPLIT(dev));
144 return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK;
147 static inline u32 /* units of 100MHz */
148 intel_fdi_link_freq(struct drm_device *dev)
151 struct drm_i915_private *dev_priv = dev->dev_private;
152 return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
157 static const intel_limit_t intel_limits_i8xx_dac = {
158 .dot = { .min = 25000, .max = 350000 },
159 .vco = { .min = 908000, .max = 1512000 },
160 .n = { .min = 2, .max = 16 },
161 .m = { .min = 96, .max = 140 },
162 .m1 = { .min = 18, .max = 26 },
163 .m2 = { .min = 6, .max = 16 },
164 .p = { .min = 4, .max = 128 },
165 .p1 = { .min = 2, .max = 33 },
166 .p2 = { .dot_limit = 165000,
167 .p2_slow = 4, .p2_fast = 2 },
170 static const intel_limit_t intel_limits_i8xx_dvo = {
171 .dot = { .min = 25000, .max = 350000 },
172 .vco = { .min = 908000, .max = 1512000 },
173 .n = { .min = 2, .max = 16 },
174 .m = { .min = 96, .max = 140 },
175 .m1 = { .min = 18, .max = 26 },
176 .m2 = { .min = 6, .max = 16 },
177 .p = { .min = 4, .max = 128 },
178 .p1 = { .min = 2, .max = 33 },
179 .p2 = { .dot_limit = 165000,
180 .p2_slow = 4, .p2_fast = 4 },
183 static const intel_limit_t intel_limits_i8xx_lvds = {
184 .dot = { .min = 25000, .max = 350000 },
185 .vco = { .min = 908000, .max = 1512000 },
186 .n = { .min = 2, .max = 16 },
187 .m = { .min = 96, .max = 140 },
188 .m1 = { .min = 18, .max = 26 },
189 .m2 = { .min = 6, .max = 16 },
190 .p = { .min = 4, .max = 128 },
191 .p1 = { .min = 1, .max = 6 },
192 .p2 = { .dot_limit = 165000,
193 .p2_slow = 14, .p2_fast = 7 },
196 static const intel_limit_t intel_limits_i9xx_sdvo = {
197 .dot = { .min = 20000, .max = 400000 },
198 .vco = { .min = 1400000, .max = 2800000 },
199 .n = { .min = 1, .max = 6 },
200 .m = { .min = 70, .max = 120 },
201 .m1 = { .min = 8, .max = 18 },
202 .m2 = { .min = 3, .max = 7 },
203 .p = { .min = 5, .max = 80 },
204 .p1 = { .min = 1, .max = 8 },
205 .p2 = { .dot_limit = 200000,
206 .p2_slow = 10, .p2_fast = 5 },
209 static const intel_limit_t intel_limits_i9xx_lvds = {
210 .dot = { .min = 20000, .max = 400000 },
211 .vco = { .min = 1400000, .max = 2800000 },
212 .n = { .min = 1, .max = 6 },
213 .m = { .min = 70, .max = 120 },
214 .m1 = { .min = 8, .max = 18 },
215 .m2 = { .min = 3, .max = 7 },
216 .p = { .min = 7, .max = 98 },
217 .p1 = { .min = 1, .max = 8 },
218 .p2 = { .dot_limit = 112000,
219 .p2_slow = 14, .p2_fast = 7 },
223 static const intel_limit_t intel_limits_g4x_sdvo = {
224 .dot = { .min = 25000, .max = 270000 },
225 .vco = { .min = 1750000, .max = 3500000},
226 .n = { .min = 1, .max = 4 },
227 .m = { .min = 104, .max = 138 },
228 .m1 = { .min = 17, .max = 23 },
229 .m2 = { .min = 5, .max = 11 },
230 .p = { .min = 10, .max = 30 },
231 .p1 = { .min = 1, .max = 3},
232 .p2 = { .dot_limit = 270000,
238 static const intel_limit_t intel_limits_g4x_hdmi = {
239 .dot = { .min = 22000, .max = 400000 },
240 .vco = { .min = 1750000, .max = 3500000},
241 .n = { .min = 1, .max = 4 },
242 .m = { .min = 104, .max = 138 },
243 .m1 = { .min = 16, .max = 23 },
244 .m2 = { .min = 5, .max = 11 },
245 .p = { .min = 5, .max = 80 },
246 .p1 = { .min = 1, .max = 8},
247 .p2 = { .dot_limit = 165000,
248 .p2_slow = 10, .p2_fast = 5 },
251 static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
252 .dot = { .min = 20000, .max = 115000 },
253 .vco = { .min = 1750000, .max = 3500000 },
254 .n = { .min = 1, .max = 3 },
255 .m = { .min = 104, .max = 138 },
256 .m1 = { .min = 17, .max = 23 },
257 .m2 = { .min = 5, .max = 11 },
258 .p = { .min = 28, .max = 112 },
259 .p1 = { .min = 2, .max = 8 },
260 .p2 = { .dot_limit = 0,
261 .p2_slow = 14, .p2_fast = 14
265 static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
266 .dot = { .min = 80000, .max = 224000 },
267 .vco = { .min = 1750000, .max = 3500000 },
268 .n = { .min = 1, .max = 3 },
269 .m = { .min = 104, .max = 138 },
270 .m1 = { .min = 17, .max = 23 },
271 .m2 = { .min = 5, .max = 11 },
272 .p = { .min = 14, .max = 42 },
273 .p1 = { .min = 2, .max = 6 },
274 .p2 = { .dot_limit = 0,
275 .p2_slow = 7, .p2_fast = 7
279 static const intel_limit_t intel_limits_pineview_sdvo = {
280 .dot = { .min = 20000, .max = 400000},
281 .vco = { .min = 1700000, .max = 3500000 },
282 /* Pineview's Ncounter is a ring counter */
283 .n = { .min = 3, .max = 6 },
284 .m = { .min = 2, .max = 256 },
285 /* Pineview only has one combined m divider, which we treat as m2. */
286 .m1 = { .min = 0, .max = 0 },
287 .m2 = { .min = 0, .max = 254 },
288 .p = { .min = 5, .max = 80 },
289 .p1 = { .min = 1, .max = 8 },
290 .p2 = { .dot_limit = 200000,
291 .p2_slow = 10, .p2_fast = 5 },
294 static const intel_limit_t intel_limits_pineview_lvds = {
295 .dot = { .min = 20000, .max = 400000 },
296 .vco = { .min = 1700000, .max = 3500000 },
297 .n = { .min = 3, .max = 6 },
298 .m = { .min = 2, .max = 256 },
299 .m1 = { .min = 0, .max = 0 },
300 .m2 = { .min = 0, .max = 254 },
301 .p = { .min = 7, .max = 112 },
302 .p1 = { .min = 1, .max = 8 },
303 .p2 = { .dot_limit = 112000,
304 .p2_slow = 14, .p2_fast = 14 },
307 /* Ironlake / Sandybridge
309 * We calculate clock using (register_value + 2) for N/M1/M2, so here
310 * the range value for them is (actual_value - 2).
312 static const intel_limit_t intel_limits_ironlake_dac = {
313 .dot = { .min = 25000, .max = 350000 },
314 .vco = { .min = 1760000, .max = 3510000 },
315 .n = { .min = 1, .max = 5 },
316 .m = { .min = 79, .max = 127 },
317 .m1 = { .min = 12, .max = 22 },
318 .m2 = { .min = 5, .max = 9 },
319 .p = { .min = 5, .max = 80 },
320 .p1 = { .min = 1, .max = 8 },
321 .p2 = { .dot_limit = 225000,
322 .p2_slow = 10, .p2_fast = 5 },
325 static const intel_limit_t intel_limits_ironlake_single_lvds = {
326 .dot = { .min = 25000, .max = 350000 },
327 .vco = { .min = 1760000, .max = 3510000 },
328 .n = { .min = 1, .max = 3 },
329 .m = { .min = 79, .max = 118 },
330 .m1 = { .min = 12, .max = 22 },
331 .m2 = { .min = 5, .max = 9 },
332 .p = { .min = 28, .max = 112 },
333 .p1 = { .min = 2, .max = 8 },
334 .p2 = { .dot_limit = 225000,
335 .p2_slow = 14, .p2_fast = 14 },
338 static const intel_limit_t intel_limits_ironlake_dual_lvds = {
339 .dot = { .min = 25000, .max = 350000 },
340 .vco = { .min = 1760000, .max = 3510000 },
341 .n = { .min = 1, .max = 3 },
342 .m = { .min = 79, .max = 127 },
343 .m1 = { .min = 12, .max = 22 },
344 .m2 = { .min = 5, .max = 9 },
345 .p = { .min = 14, .max = 56 },
346 .p1 = { .min = 2, .max = 8 },
347 .p2 = { .dot_limit = 225000,
348 .p2_slow = 7, .p2_fast = 7 },
351 /* LVDS 100mhz refclk limits. */
352 static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
353 .dot = { .min = 25000, .max = 350000 },
354 .vco = { .min = 1760000, .max = 3510000 },
355 .n = { .min = 1, .max = 2 },
356 .m = { .min = 79, .max = 126 },
357 .m1 = { .min = 12, .max = 22 },
358 .m2 = { .min = 5, .max = 9 },
359 .p = { .min = 28, .max = 112 },
360 .p1 = { .min = 2, .max = 8 },
361 .p2 = { .dot_limit = 225000,
362 .p2_slow = 14, .p2_fast = 14 },
365 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
366 .dot = { .min = 25000, .max = 350000 },
367 .vco = { .min = 1760000, .max = 3510000 },
368 .n = { .min = 1, .max = 3 },
369 .m = { .min = 79, .max = 126 },
370 .m1 = { .min = 12, .max = 22 },
371 .m2 = { .min = 5, .max = 9 },
372 .p = { .min = 14, .max = 42 },
373 .p1 = { .min = 2, .max = 6 },
374 .p2 = { .dot_limit = 225000,
375 .p2_slow = 7, .p2_fast = 7 },
378 static const intel_limit_t intel_limits_vlv = {
380 * These are the data rate limits (measured in fast clocks)
381 * since those are the strictest limits we have. The fast
382 * clock and actual rate limits are more relaxed, so checking
383 * them would make no difference.
385 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
386 .vco = { .min = 4000000, .max = 6000000 },
387 .n = { .min = 1, .max = 7 },
388 .m1 = { .min = 2, .max = 3 },
389 .m2 = { .min = 11, .max = 156 },
390 .p1 = { .min = 2, .max = 3 },
391 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
394 static const intel_limit_t intel_limits_chv = {
396 * These are the data rate limits (measured in fast clocks)
397 * since those are the strictest limits we have. The fast
398 * clock and actual rate limits are more relaxed, so checking
399 * them would make no difference.
401 .dot = { .min = 25000 * 5, .max = 540000 * 5},
402 .vco = { .min = 4800000, .max = 6480000 },
403 .n = { .min = 1, .max = 1 },
404 .m1 = { .min = 2, .max = 2 },
405 .m2 = { .min = 24 << 22, .max = 175 << 22 },
406 .p1 = { .min = 2, .max = 4 },
407 .p2 = { .p2_slow = 1, .p2_fast = 14 },
410 static const intel_limit_t intel_limits_bxt = {
411 /* FIXME: find real dot limits */
412 .dot = { .min = 0, .max = INT_MAX },
413 .vco = { .min = 4800000, .max = 6700000 },
414 .n = { .min = 1, .max = 1 },
415 .m1 = { .min = 2, .max = 2 },
416 /* FIXME: find real m2 limits */
417 .m2 = { .min = 2 << 22, .max = 255 << 22 },
418 .p1 = { .min = 2, .max = 4 },
419 .p2 = { .p2_slow = 1, .p2_fast = 20 },
423 needs_modeset(struct drm_crtc_state *state)
425 return state->mode_changed || state->active_changed;
429 * Returns whether any output on the specified pipe is of the specified type
431 bool intel_pipe_has_type(struct intel_crtc *crtc, enum intel_output_type type)
433 struct drm_device *dev = crtc->base.dev;
434 struct intel_encoder *encoder;
436 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
437 if (encoder->type == type)
444 * Returns whether any output on the specified pipe will have the specified
445 * type after a staged modeset is complete, i.e., the same as
446 * intel_pipe_has_type() but looking at encoder->new_crtc instead of
449 static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state,
452 struct drm_atomic_state *state = crtc_state->base.state;
453 struct drm_connector *connector;
454 struct drm_connector_state *connector_state;
455 struct intel_encoder *encoder;
456 int i, num_connectors = 0;
458 for_each_connector_in_state(state, connector, connector_state, i) {
459 if (connector_state->crtc != crtc_state->base.crtc)
464 encoder = to_intel_encoder(connector_state->best_encoder);
465 if (encoder->type == type)
469 WARN_ON(num_connectors == 0);
474 static const intel_limit_t *
475 intel_ironlake_limit(struct intel_crtc_state *crtc_state, int refclk)
477 struct drm_device *dev = crtc_state->base.crtc->dev;
478 const intel_limit_t *limit;
480 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) {
481 if (intel_is_dual_link_lvds(dev)) {
482 if (refclk == 100000)
483 limit = &intel_limits_ironlake_dual_lvds_100m;
485 limit = &intel_limits_ironlake_dual_lvds;
487 if (refclk == 100000)
488 limit = &intel_limits_ironlake_single_lvds_100m;
490 limit = &intel_limits_ironlake_single_lvds;
493 limit = &intel_limits_ironlake_dac;
498 static const intel_limit_t *
499 intel_g4x_limit(struct intel_crtc_state *crtc_state)
501 struct drm_device *dev = crtc_state->base.crtc->dev;
502 const intel_limit_t *limit;
504 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) {
505 if (intel_is_dual_link_lvds(dev))
506 limit = &intel_limits_g4x_dual_channel_lvds;
508 limit = &intel_limits_g4x_single_channel_lvds;
509 } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) ||
510 intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
511 limit = &intel_limits_g4x_hdmi;
512 } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) {
513 limit = &intel_limits_g4x_sdvo;
514 } else /* The option is for other outputs */
515 limit = &intel_limits_i9xx_sdvo;
520 static const intel_limit_t *
521 intel_limit(struct intel_crtc_state *crtc_state, int refclk)
523 struct drm_device *dev = crtc_state->base.crtc->dev;
524 const intel_limit_t *limit;
527 limit = &intel_limits_bxt;
528 else if (HAS_PCH_SPLIT(dev))
529 limit = intel_ironlake_limit(crtc_state, refclk);
530 else if (IS_G4X(dev)) {
531 limit = intel_g4x_limit(crtc_state);
532 } else if (IS_PINEVIEW(dev)) {
533 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS))
534 limit = &intel_limits_pineview_lvds;
536 limit = &intel_limits_pineview_sdvo;
537 } else if (IS_CHERRYVIEW(dev)) {
538 limit = &intel_limits_chv;
539 } else if (IS_VALLEYVIEW(dev)) {
540 limit = &intel_limits_vlv;
541 } else if (!IS_GEN2(dev)) {
542 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS))
543 limit = &intel_limits_i9xx_lvds;
545 limit = &intel_limits_i9xx_sdvo;
547 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS))
548 limit = &intel_limits_i8xx_lvds;
549 else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO))
550 limit = &intel_limits_i8xx_dvo;
552 limit = &intel_limits_i8xx_dac;
558 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
559 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
560 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
561 * The helpers' return value is the rate of the clock that is fed to the
562 * display engine's pipe which can be the above fast dot clock rate or a
563 * divided-down version of it.
565 /* m1 is reserved as 0 in Pineview, n is a ring counter */
566 static int pnv_calc_dpll_params(int refclk, intel_clock_t *clock)
568 clock->m = clock->m2 + 2;
569 clock->p = clock->p1 * clock->p2;
570 if (WARN_ON(clock->n == 0 || clock->p == 0))
572 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
573 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
578 static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
580 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
583 static int i9xx_calc_dpll_params(int refclk, intel_clock_t *clock)
585 clock->m = i9xx_dpll_compute_m(clock);
586 clock->p = clock->p1 * clock->p2;
587 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
589 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
590 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
595 static int vlv_calc_dpll_params(int refclk, intel_clock_t *clock)
597 clock->m = clock->m1 * clock->m2;
598 clock->p = clock->p1 * clock->p2;
599 if (WARN_ON(clock->n == 0 || clock->p == 0))
601 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
602 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
604 return clock->dot / 5;
607 int chv_calc_dpll_params(int refclk, intel_clock_t *clock)
609 clock->m = clock->m1 * clock->m2;
610 clock->p = clock->p1 * clock->p2;
611 if (WARN_ON(clock->n == 0 || clock->p == 0))
613 clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
615 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
617 return clock->dot / 5;
620 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
622 * Returns whether the given set of divisors are valid for a given refclk with
623 * the given connectors.
626 static bool intel_PLL_is_valid(struct drm_device *dev,
627 const intel_limit_t *limit,
628 const intel_clock_t *clock)
630 if (clock->n < limit->n.min || limit->n.max < clock->n)
631 INTELPllInvalid("n out of range\n");
632 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
633 INTELPllInvalid("p1 out of range\n");
634 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
635 INTELPllInvalid("m2 out of range\n");
636 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
637 INTELPllInvalid("m1 out of range\n");
639 if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev) && !IS_BROXTON(dev))
640 if (clock->m1 <= clock->m2)
641 INTELPllInvalid("m1 <= m2\n");
643 if (!IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) {
644 if (clock->p < limit->p.min || limit->p.max < clock->p)
645 INTELPllInvalid("p out of range\n");
646 if (clock->m < limit->m.min || limit->m.max < clock->m)
647 INTELPllInvalid("m out of range\n");
650 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
651 INTELPllInvalid("vco out of range\n");
652 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
653 * connector, etc., rather than just a single range.
655 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
656 INTELPllInvalid("dot out of range\n");
662 i9xx_select_p2_div(const intel_limit_t *limit,
663 const struct intel_crtc_state *crtc_state,
666 struct drm_device *dev = crtc_state->base.crtc->dev;
668 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) {
670 * For LVDS just rely on its current settings for dual-channel.
671 * We haven't figured out how to reliably set up different
672 * single/dual channel state, if we even can.
674 if (intel_is_dual_link_lvds(dev))
675 return limit->p2.p2_fast;
677 return limit->p2.p2_slow;
679 if (target < limit->p2.dot_limit)
680 return limit->p2.p2_slow;
682 return limit->p2.p2_fast;
687 i9xx_find_best_dpll(const intel_limit_t *limit,
688 struct intel_crtc_state *crtc_state,
689 int target, int refclk, intel_clock_t *match_clock,
690 intel_clock_t *best_clock)
692 struct drm_device *dev = crtc_state->base.crtc->dev;
696 memset(best_clock, 0, sizeof(*best_clock));
698 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
700 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
702 for (clock.m2 = limit->m2.min;
703 clock.m2 <= limit->m2.max; clock.m2++) {
704 if (clock.m2 >= clock.m1)
706 for (clock.n = limit->n.min;
707 clock.n <= limit->n.max; clock.n++) {
708 for (clock.p1 = limit->p1.min;
709 clock.p1 <= limit->p1.max; clock.p1++) {
712 i9xx_calc_dpll_params(refclk, &clock);
713 if (!intel_PLL_is_valid(dev, limit,
717 clock.p != match_clock->p)
720 this_err = abs(clock.dot - target);
721 if (this_err < err) {
730 return (err != target);
734 pnv_find_best_dpll(const intel_limit_t *limit,
735 struct intel_crtc_state *crtc_state,
736 int target, int refclk, intel_clock_t *match_clock,
737 intel_clock_t *best_clock)
739 struct drm_device *dev = crtc_state->base.crtc->dev;
743 memset(best_clock, 0, sizeof(*best_clock));
745 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
747 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
749 for (clock.m2 = limit->m2.min;
750 clock.m2 <= limit->m2.max; clock.m2++) {
751 for (clock.n = limit->n.min;
752 clock.n <= limit->n.max; clock.n++) {
753 for (clock.p1 = limit->p1.min;
754 clock.p1 <= limit->p1.max; clock.p1++) {
757 pnv_calc_dpll_params(refclk, &clock);
758 if (!intel_PLL_is_valid(dev, limit,
762 clock.p != match_clock->p)
765 this_err = abs(clock.dot - target);
766 if (this_err < err) {
775 return (err != target);
779 g4x_find_best_dpll(const intel_limit_t *limit,
780 struct intel_crtc_state *crtc_state,
781 int target, int refclk, intel_clock_t *match_clock,
782 intel_clock_t *best_clock)
784 struct drm_device *dev = crtc_state->base.crtc->dev;
788 /* approximately equals target * 0.00585 */
789 int err_most = (target >> 8) + (target >> 9);
791 memset(best_clock, 0, sizeof(*best_clock));
793 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
795 max_n = limit->n.max;
796 /* based on hardware requirement, prefer smaller n to precision */
797 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
798 /* based on hardware requirement, prefere larger m1,m2 */
799 for (clock.m1 = limit->m1.max;
800 clock.m1 >= limit->m1.min; clock.m1--) {
801 for (clock.m2 = limit->m2.max;
802 clock.m2 >= limit->m2.min; clock.m2--) {
803 for (clock.p1 = limit->p1.max;
804 clock.p1 >= limit->p1.min; clock.p1--) {
807 i9xx_calc_dpll_params(refclk, &clock);
808 if (!intel_PLL_is_valid(dev, limit,
812 this_err = abs(clock.dot - target);
813 if (this_err < err_most) {
827 * Check if the calculated PLL configuration is more optimal compared to the
828 * best configuration and error found so far. Return the calculated error.
830 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
831 const intel_clock_t *calculated_clock,
832 const intel_clock_t *best_clock,
833 unsigned int best_error_ppm,
834 unsigned int *error_ppm)
837 * For CHV ignore the error and consider only the P value.
838 * Prefer a bigger P value based on HW requirements.
840 if (IS_CHERRYVIEW(dev)) {
843 return calculated_clock->p > best_clock->p;
846 if (WARN_ON_ONCE(!target_freq))
849 *error_ppm = div_u64(1000000ULL *
850 abs(target_freq - calculated_clock->dot),
853 * Prefer a better P value over a better (smaller) error if the error
854 * is small. Ensure this preference for future configurations too by
855 * setting the error to 0.
857 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
863 return *error_ppm + 10 < best_error_ppm;
867 vlv_find_best_dpll(const intel_limit_t *limit,
868 struct intel_crtc_state *crtc_state,
869 int target, int refclk, intel_clock_t *match_clock,
870 intel_clock_t *best_clock)
872 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
873 struct drm_device *dev = crtc->base.dev;
875 unsigned int bestppm = 1000000;
876 /* min update 19.2 MHz */
877 int max_n = min(limit->n.max, refclk / 19200);
880 target *= 5; /* fast clock */
882 memset(best_clock, 0, sizeof(*best_clock));
884 /* based on hardware requirement, prefer smaller n to precision */
885 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
886 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
887 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
888 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
889 clock.p = clock.p1 * clock.p2;
890 /* based on hardware requirement, prefer bigger m1,m2 values */
891 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
894 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
897 vlv_calc_dpll_params(refclk, &clock);
899 if (!intel_PLL_is_valid(dev, limit,
903 if (!vlv_PLL_is_optimal(dev, target,
921 chv_find_best_dpll(const intel_limit_t *limit,
922 struct intel_crtc_state *crtc_state,
923 int target, int refclk, intel_clock_t *match_clock,
924 intel_clock_t *best_clock)
926 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
927 struct drm_device *dev = crtc->base.dev;
928 unsigned int best_error_ppm;
933 memset(best_clock, 0, sizeof(*best_clock));
934 best_error_ppm = 1000000;
937 * Based on hardware doc, the n always set to 1, and m1 always
938 * set to 2. If requires to support 200Mhz refclk, we need to
939 * revisit this because n may not 1 anymore.
941 clock.n = 1, clock.m1 = 2;
942 target *= 5; /* fast clock */
944 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
945 for (clock.p2 = limit->p2.p2_fast;
946 clock.p2 >= limit->p2.p2_slow;
947 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
948 unsigned int error_ppm;
950 clock.p = clock.p1 * clock.p2;
952 m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
953 clock.n) << 22, refclk * clock.m1);
955 if (m2 > INT_MAX/clock.m1)
960 chv_calc_dpll_params(refclk, &clock);
962 if (!intel_PLL_is_valid(dev, limit, &clock))
965 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
966 best_error_ppm, &error_ppm))
970 best_error_ppm = error_ppm;
978 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock,
979 intel_clock_t *best_clock)
981 int refclk = i9xx_get_refclk(crtc_state, 0);
983 return chv_find_best_dpll(intel_limit(crtc_state, refclk), crtc_state,
984 target_clock, refclk, NULL, best_clock);
987 bool intel_crtc_active(struct drm_crtc *crtc)
989 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
991 /* Be paranoid as we can arrive here with only partial
992 * state retrieved from the hardware during setup.
994 * We can ditch the adjusted_mode.crtc_clock check as soon
995 * as Haswell has gained clock readout/fastboot support.
997 * We can ditch the crtc->primary->fb check as soon as we can
998 * properly reconstruct framebuffers.
1000 * FIXME: The intel_crtc->active here should be switched to
1001 * crtc->state->active once we have proper CRTC states wired up
1004 return intel_crtc->active && crtc->primary->state->fb &&
1005 intel_crtc->config->base.adjusted_mode.crtc_clock;
1008 enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
1011 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
1012 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1014 return intel_crtc->config->cpu_transcoder;
1017 static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe)
1019 struct drm_i915_private *dev_priv = dev->dev_private;
1020 u32 reg = PIPEDSL(pipe);
1025 line_mask = DSL_LINEMASK_GEN2;
1027 line_mask = DSL_LINEMASK_GEN3;
1029 line1 = I915_READ(reg) & line_mask;
1031 line2 = I915_READ(reg) & line_mask;
1033 return line1 == line2;
1037 * intel_wait_for_pipe_off - wait for pipe to turn off
1038 * @crtc: crtc whose pipe to wait for
1040 * After disabling a pipe, we can't wait for vblank in the usual way,
1041 * spinning on the vblank interrupt status bit, since we won't actually
1042 * see an interrupt when the pipe is disabled.
1044 * On Gen4 and above:
1045 * wait for the pipe register state bit to turn off
1048 * wait for the display line value to settle (it usually
1049 * ends up stopping at the start of the next frame).
1052 static void intel_wait_for_pipe_off(struct intel_crtc *crtc)
1054 struct drm_device *dev = crtc->base.dev;
1055 struct drm_i915_private *dev_priv = dev->dev_private;
1056 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
1057 enum pipe pipe = crtc->pipe;
1059 if (INTEL_INFO(dev)->gen >= 4) {
1060 int reg = PIPECONF(cpu_transcoder);
1062 /* Wait for the Pipe State to go off */
1063 if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
1065 WARN(1, "pipe_off wait timed out\n");
1067 /* Wait for the display line to settle */
1068 if (wait_for(pipe_dsl_stopped(dev, pipe), 100))
1069 WARN(1, "pipe_off wait timed out\n");
1074 * ibx_digital_port_connected - is the specified port connected?
1075 * @dev_priv: i915 private structure
1076 * @port: the port to test
1078 * Returns true if @port is connected, false otherwise.
1080 bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
1081 struct intel_digital_port *port)
1085 if (HAS_PCH_IBX(dev_priv->dev)) {
1086 switch (port->port) {
1088 bit = SDE_PORTB_HOTPLUG;
1091 bit = SDE_PORTC_HOTPLUG;
1094 bit = SDE_PORTD_HOTPLUG;
1100 switch (port->port) {
1102 bit = SDE_PORTB_HOTPLUG_CPT;
1105 bit = SDE_PORTC_HOTPLUG_CPT;
1108 bit = SDE_PORTD_HOTPLUG_CPT;
1115 return I915_READ(SDEISR) & bit;
1118 static const char *state_string(bool enabled)
1120 return enabled ? "on" : "off";
1123 /* Only for pre-ILK configs */
1124 void assert_pll(struct drm_i915_private *dev_priv,
1125 enum pipe pipe, bool state)
1132 val = I915_READ(reg);
1133 cur_state = !!(val & DPLL_VCO_ENABLE);
1134 I915_STATE_WARN(cur_state != state,
1135 "PLL state assertion failure (expected %s, current %s)\n",
1136 state_string(state), state_string(cur_state));
1139 /* XXX: the dsi pll is shared between MIPI DSI ports */
1140 static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
1145 mutex_lock(&dev_priv->sb_lock);
1146 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1147 mutex_unlock(&dev_priv->sb_lock);
1149 cur_state = val & DSI_PLL_VCO_EN;
1150 I915_STATE_WARN(cur_state != state,
1151 "DSI PLL state assertion failure (expected %s, current %s)\n",
1152 state_string(state), state_string(cur_state));
1154 #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
1155 #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
1157 struct intel_shared_dpll *
1158 intel_crtc_to_shared_dpll(struct intel_crtc *crtc)
1160 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
1162 if (crtc->config->shared_dpll < 0)
1165 return &dev_priv->shared_dplls[crtc->config->shared_dpll];
1169 void assert_shared_dpll(struct drm_i915_private *dev_priv,
1170 struct intel_shared_dpll *pll,
1174 struct intel_dpll_hw_state hw_state;
1177 "asserting DPLL %s with no DPLL\n", state_string(state)))
1180 cur_state = pll->get_hw_state(dev_priv, pll, &hw_state);
1181 I915_STATE_WARN(cur_state != state,
1182 "%s assertion failure (expected %s, current %s)\n",
1183 pll->name, state_string(state), state_string(cur_state));
1186 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1187 enum pipe pipe, bool state)
1192 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1195 if (HAS_DDI(dev_priv->dev)) {
1196 /* DDI does not have a specific FDI_TX register */
1197 reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
1198 val = I915_READ(reg);
1199 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1201 reg = FDI_TX_CTL(pipe);
1202 val = I915_READ(reg);
1203 cur_state = !!(val & FDI_TX_ENABLE);
1205 I915_STATE_WARN(cur_state != state,
1206 "FDI TX state assertion failure (expected %s, current %s)\n",
1207 state_string(state), state_string(cur_state));
1209 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1210 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1212 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1213 enum pipe pipe, bool state)
1219 reg = FDI_RX_CTL(pipe);
1220 val = I915_READ(reg);
1221 cur_state = !!(val & FDI_RX_ENABLE);
1222 I915_STATE_WARN(cur_state != state,
1223 "FDI RX state assertion failure (expected %s, current %s)\n",
1224 state_string(state), state_string(cur_state));
1226 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1227 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1229 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1235 /* ILK FDI PLL is always enabled */
1236 if (INTEL_INFO(dev_priv->dev)->gen == 5)
1239 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1240 if (HAS_DDI(dev_priv->dev))
1243 reg = FDI_TX_CTL(pipe);
1244 val = I915_READ(reg);
1245 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1248 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1249 enum pipe pipe, bool state)
1255 reg = FDI_RX_CTL(pipe);
1256 val = I915_READ(reg);
1257 cur_state = !!(val & FDI_RX_PLL_ENABLE);
1258 I915_STATE_WARN(cur_state != state,
1259 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1260 state_string(state), state_string(cur_state));
1263 void assert_panel_unlocked(struct drm_i915_private *dev_priv,
1266 struct drm_device *dev = dev_priv->dev;
1269 enum pipe panel_pipe = PIPE_A;
1272 if (WARN_ON(HAS_DDI(dev)))
1275 if (HAS_PCH_SPLIT(dev)) {
1278 pp_reg = PCH_PP_CONTROL;
1279 port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK;
1281 if (port_sel == PANEL_PORT_SELECT_LVDS &&
1282 I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT)
1283 panel_pipe = PIPE_B;
1284 /* XXX: else fix for eDP */
1285 } else if (IS_VALLEYVIEW(dev)) {
1286 /* presumably write lock depends on pipe, not port select */
1287 pp_reg = VLV_PIPE_PP_CONTROL(pipe);
1290 pp_reg = PP_CONTROL;
1291 if (I915_READ(LVDS) & LVDS_PIPEB_SELECT)
1292 panel_pipe = PIPE_B;
1295 val = I915_READ(pp_reg);
1296 if (!(val & PANEL_POWER_ON) ||
1297 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1300 I915_STATE_WARN(panel_pipe == pipe && locked,
1301 "panel assertion failure, pipe %c regs locked\n",
1305 static void assert_cursor(struct drm_i915_private *dev_priv,
1306 enum pipe pipe, bool state)
1308 struct drm_device *dev = dev_priv->dev;
1311 if (IS_845G(dev) || IS_I865G(dev))
1312 cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
1314 cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
1316 I915_STATE_WARN(cur_state != state,
1317 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1318 pipe_name(pipe), state_string(state), state_string(cur_state));
1320 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1321 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1323 void assert_pipe(struct drm_i915_private *dev_priv,
1324 enum pipe pipe, bool state)
1329 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1332 /* if we need the pipe quirk it must be always on */
1333 if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
1334 (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
1337 if (!intel_display_power_is_enabled(dev_priv,
1338 POWER_DOMAIN_TRANSCODER(cpu_transcoder))) {
1341 reg = PIPECONF(cpu_transcoder);
1342 val = I915_READ(reg);
1343 cur_state = !!(val & PIPECONF_ENABLE);
1346 I915_STATE_WARN(cur_state != state,
1347 "pipe %c assertion failure (expected %s, current %s)\n",
1348 pipe_name(pipe), state_string(state), state_string(cur_state));
1351 static void assert_plane(struct drm_i915_private *dev_priv,
1352 enum plane plane, bool state)
1358 reg = DSPCNTR(plane);
1359 val = I915_READ(reg);
1360 cur_state = !!(val & DISPLAY_PLANE_ENABLE);
1361 I915_STATE_WARN(cur_state != state,
1362 "plane %c assertion failure (expected %s, current %s)\n",
1363 plane_name(plane), state_string(state), state_string(cur_state));
1366 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1367 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1369 static void assert_planes_disabled(struct drm_i915_private *dev_priv,
1372 struct drm_device *dev = dev_priv->dev;
1377 /* Primary planes are fixed to pipes on gen4+ */
1378 if (INTEL_INFO(dev)->gen >= 4) {
1379 reg = DSPCNTR(pipe);
1380 val = I915_READ(reg);
1381 I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE,
1382 "plane %c assertion failure, should be disabled but not\n",
1387 /* Need to check both planes against the pipe */
1388 for_each_pipe(dev_priv, i) {
1390 val = I915_READ(reg);
1391 cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
1392 DISPPLANE_SEL_PIPE_SHIFT;
1393 I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
1394 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1395 plane_name(i), pipe_name(pipe));
1399 static void assert_sprites_disabled(struct drm_i915_private *dev_priv,
1402 struct drm_device *dev = dev_priv->dev;
1406 if (INTEL_INFO(dev)->gen >= 9) {
1407 for_each_sprite(dev_priv, pipe, sprite) {
1408 val = I915_READ(PLANE_CTL(pipe, sprite));
1409 I915_STATE_WARN(val & PLANE_CTL_ENABLE,
1410 "plane %d assertion failure, should be off on pipe %c but is still active\n",
1411 sprite, pipe_name(pipe));
1413 } else if (IS_VALLEYVIEW(dev)) {
1414 for_each_sprite(dev_priv, pipe, sprite) {
1415 reg = SPCNTR(pipe, sprite);
1416 val = I915_READ(reg);
1417 I915_STATE_WARN(val & SP_ENABLE,
1418 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1419 sprite_name(pipe, sprite), pipe_name(pipe));
1421 } else if (INTEL_INFO(dev)->gen >= 7) {
1423 val = I915_READ(reg);
1424 I915_STATE_WARN(val & SPRITE_ENABLE,
1425 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1426 plane_name(pipe), pipe_name(pipe));
1427 } else if (INTEL_INFO(dev)->gen >= 5) {
1428 reg = DVSCNTR(pipe);
1429 val = I915_READ(reg);
1430 I915_STATE_WARN(val & DVS_ENABLE,
1431 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1432 plane_name(pipe), pipe_name(pipe));
1436 static void assert_vblank_disabled(struct drm_crtc *crtc)
1438 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1439 drm_crtc_vblank_put(crtc);
1442 static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
1447 I915_STATE_WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev)));
1449 val = I915_READ(PCH_DREF_CONTROL);
1450 enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
1451 DREF_SUPERSPREAD_SOURCE_MASK));
1452 I915_STATE_WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
1455 static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1462 reg = PCH_TRANSCONF(pipe);
1463 val = I915_READ(reg);
1464 enabled = !!(val & TRANS_ENABLE);
1465 I915_STATE_WARN(enabled,
1466 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1470 static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
1471 enum pipe pipe, u32 port_sel, u32 val)
1473 if ((val & DP_PORT_EN) == 0)
1476 if (HAS_PCH_CPT(dev_priv->dev)) {
1477 u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe);
1478 u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg);
1479 if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
1481 } else if (IS_CHERRYVIEW(dev_priv->dev)) {
1482 if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe))
1485 if ((val & DP_PIPE_MASK) != (pipe << 30))
1491 static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
1492 enum pipe pipe, u32 val)
1494 if ((val & SDVO_ENABLE) == 0)
1497 if (HAS_PCH_CPT(dev_priv->dev)) {
1498 if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
1500 } else if (IS_CHERRYVIEW(dev_priv->dev)) {
1501 if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe))
1504 if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe))
1510 static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
1511 enum pipe pipe, u32 val)
1513 if ((val & LVDS_PORT_EN) == 0)
1516 if (HAS_PCH_CPT(dev_priv->dev)) {
1517 if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
1520 if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
1526 static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
1527 enum pipe pipe, u32 val)
1529 if ((val & ADPA_DAC_ENABLE) == 0)
1531 if (HAS_PCH_CPT(dev_priv->dev)) {
1532 if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
1535 if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
1541 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1542 enum pipe pipe, int reg, u32 port_sel)
1544 u32 val = I915_READ(reg);
1545 I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
1546 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1547 reg, pipe_name(pipe));
1549 I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
1550 && (val & DP_PIPEB_SELECT),
1551 "IBX PCH dp port still using transcoder B\n");
1554 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1555 enum pipe pipe, int reg)
1557 u32 val = I915_READ(reg);
1558 I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
1559 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1560 reg, pipe_name(pipe));
1562 I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0
1563 && (val & SDVO_PIPE_B_SELECT),
1564 "IBX PCH hdmi port still using transcoder B\n");
1567 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1573 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
1574 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
1575 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
1578 val = I915_READ(reg);
1579 I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val),
1580 "PCH VGA enabled on transcoder %c, should be disabled\n",
1584 val = I915_READ(reg);
1585 I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val),
1586 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1589 assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB);
1590 assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC);
1591 assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
1594 static void intel_init_dpio(struct drm_device *dev)
1596 struct drm_i915_private *dev_priv = dev->dev_private;
1598 if (!IS_VALLEYVIEW(dev))
1602 * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
1603 * CHV x1 PHY (DP/HDMI D)
1604 * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
1606 if (IS_CHERRYVIEW(dev)) {
1607 DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2;
1608 DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO;
1610 DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO;
1614 static void vlv_enable_pll(struct intel_crtc *crtc,
1615 const struct intel_crtc_state *pipe_config)
1617 struct drm_device *dev = crtc->base.dev;
1618 struct drm_i915_private *dev_priv = dev->dev_private;
1619 int reg = DPLL(crtc->pipe);
1620 u32 dpll = pipe_config->dpll_hw_state.dpll;
1622 assert_pipe_disabled(dev_priv, crtc->pipe);
1624 /* No really, not for ILK+ */
1625 BUG_ON(!IS_VALLEYVIEW(dev_priv->dev));
1627 /* PLL is protected by panel, make sure we can write it */
1628 if (IS_MOBILE(dev_priv->dev))
1629 assert_panel_unlocked(dev_priv, crtc->pipe);
1631 I915_WRITE(reg, dpll);
1635 if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
1636 DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe);
1638 I915_WRITE(DPLL_MD(crtc->pipe), pipe_config->dpll_hw_state.dpll_md);
1639 POSTING_READ(DPLL_MD(crtc->pipe));
1641 /* We do this three times for luck */
1642 I915_WRITE(reg, dpll);
1644 udelay(150); /* wait for warmup */
1645 I915_WRITE(reg, dpll);
1647 udelay(150); /* wait for warmup */
1648 I915_WRITE(reg, dpll);
1650 udelay(150); /* wait for warmup */
1653 static void chv_enable_pll(struct intel_crtc *crtc,
1654 const struct intel_crtc_state *pipe_config)
1656 struct drm_device *dev = crtc->base.dev;
1657 struct drm_i915_private *dev_priv = dev->dev_private;
1658 int pipe = crtc->pipe;
1659 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1662 assert_pipe_disabled(dev_priv, crtc->pipe);
1664 BUG_ON(!IS_CHERRYVIEW(dev_priv->dev));
1666 mutex_lock(&dev_priv->sb_lock);
1668 /* Enable back the 10bit clock to display controller */
1669 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1670 tmp |= DPIO_DCLKP_EN;
1671 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1673 mutex_unlock(&dev_priv->sb_lock);
1676 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1681 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1683 /* Check PLL is locked */
1684 if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
1685 DRM_ERROR("PLL %d failed to lock\n", pipe);
1687 /* not sure when this should be written */
1688 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1689 POSTING_READ(DPLL_MD(pipe));
1692 static int intel_num_dvo_pipes(struct drm_device *dev)
1694 struct intel_crtc *crtc;
1697 for_each_intel_crtc(dev, crtc)
1698 count += crtc->base.state->active &&
1699 intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO);
1704 static void i9xx_enable_pll(struct intel_crtc *crtc)
1706 struct drm_device *dev = crtc->base.dev;
1707 struct drm_i915_private *dev_priv = dev->dev_private;
1708 int reg = DPLL(crtc->pipe);
1709 u32 dpll = crtc->config->dpll_hw_state.dpll;
1711 assert_pipe_disabled(dev_priv, crtc->pipe);
1713 /* No really, not for ILK+ */
1714 BUG_ON(INTEL_INFO(dev)->gen >= 5);
1716 /* PLL is protected by panel, make sure we can write it */
1717 if (IS_MOBILE(dev) && !IS_I830(dev))
1718 assert_panel_unlocked(dev_priv, crtc->pipe);
1720 /* Enable DVO 2x clock on both PLLs if necessary */
1721 if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) {
1723 * It appears to be important that we don't enable this
1724 * for the current pipe before otherwise configuring the
1725 * PLL. No idea how this should be handled if multiple
1726 * DVO outputs are enabled simultaneosly.
1728 dpll |= DPLL_DVO_2X_MODE;
1729 I915_WRITE(DPLL(!crtc->pipe),
1730 I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
1733 /* Wait for the clocks to stabilize. */
1737 if (INTEL_INFO(dev)->gen >= 4) {
1738 I915_WRITE(DPLL_MD(crtc->pipe),
1739 crtc->config->dpll_hw_state.dpll_md);
1741 /* The pixel multiplier can only be updated once the
1742 * DPLL is enabled and the clocks are stable.
1744 * So write it again.
1746 I915_WRITE(reg, dpll);
1749 /* We do this three times for luck */
1750 I915_WRITE(reg, dpll);
1752 udelay(150); /* wait for warmup */
1753 I915_WRITE(reg, dpll);
1755 udelay(150); /* wait for warmup */
1756 I915_WRITE(reg, dpll);
1758 udelay(150); /* wait for warmup */
1762 * i9xx_disable_pll - disable a PLL
1763 * @dev_priv: i915 private structure
1764 * @pipe: pipe PLL to disable
1766 * Disable the PLL for @pipe, making sure the pipe is off first.
1768 * Note! This is for pre-ILK only.
1770 static void i9xx_disable_pll(struct intel_crtc *crtc)
1772 struct drm_device *dev = crtc->base.dev;
1773 struct drm_i915_private *dev_priv = dev->dev_private;
1774 enum pipe pipe = crtc->pipe;
1776 /* Disable DVO 2x clock on both PLLs if necessary */
1778 intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) &&
1779 !intel_num_dvo_pipes(dev)) {
1780 I915_WRITE(DPLL(PIPE_B),
1781 I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
1782 I915_WRITE(DPLL(PIPE_A),
1783 I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
1786 /* Don't disable pipe or pipe PLLs if needed */
1787 if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
1788 (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
1791 /* Make sure the pipe isn't still relying on us */
1792 assert_pipe_disabled(dev_priv, pipe);
1794 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
1795 POSTING_READ(DPLL(pipe));
1798 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1802 /* Make sure the pipe isn't still relying on us */
1803 assert_pipe_disabled(dev_priv, pipe);
1806 * Leave integrated clock source and reference clock enabled for pipe B.
1807 * The latter is needed for VGA hotplug / manual detection.
1809 val = DPLL_VGA_MODE_DIS;
1811 val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REF_CLK_ENABLE_VLV;
1812 I915_WRITE(DPLL(pipe), val);
1813 POSTING_READ(DPLL(pipe));
1817 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1819 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1822 /* Make sure the pipe isn't still relying on us */
1823 assert_pipe_disabled(dev_priv, pipe);
1825 /* Set PLL en = 0 */
1826 val = DPLL_SSC_REF_CLK_CHV |
1827 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1829 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1830 I915_WRITE(DPLL(pipe), val);
1831 POSTING_READ(DPLL(pipe));
1833 mutex_lock(&dev_priv->sb_lock);
1835 /* Disable 10bit clock to display controller */
1836 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1837 val &= ~DPIO_DCLKP_EN;
1838 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1840 /* disable left/right clock distribution */
1841 if (pipe != PIPE_B) {
1842 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
1843 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
1844 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
1846 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
1847 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
1848 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
1851 mutex_unlock(&dev_priv->sb_lock);
1854 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1855 struct intel_digital_port *dport,
1856 unsigned int expected_mask)
1861 switch (dport->port) {
1863 port_mask = DPLL_PORTB_READY_MASK;
1867 port_mask = DPLL_PORTC_READY_MASK;
1869 expected_mask <<= 4;
1872 port_mask = DPLL_PORTD_READY_MASK;
1873 dpll_reg = DPIO_PHY_STATUS;
1879 if (wait_for((I915_READ(dpll_reg) & port_mask) == expected_mask, 1000))
1880 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1881 port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask);
1884 static void intel_prepare_shared_dpll(struct intel_crtc *crtc)
1886 struct drm_device *dev = crtc->base.dev;
1887 struct drm_i915_private *dev_priv = dev->dev_private;
1888 struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
1890 if (WARN_ON(pll == NULL))
1893 WARN_ON(!pll->config.crtc_mask);
1894 if (pll->active == 0) {
1895 DRM_DEBUG_DRIVER("setting up %s\n", pll->name);
1897 assert_shared_dpll_disabled(dev_priv, pll);
1899 pll->mode_set(dev_priv, pll);
1904 * intel_enable_shared_dpll - enable PCH PLL
1905 * @dev_priv: i915 private structure
1906 * @pipe: pipe PLL to enable
1908 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1909 * drives the transcoder clock.
1911 static void intel_enable_shared_dpll(struct intel_crtc *crtc)
1913 struct drm_device *dev = crtc->base.dev;
1914 struct drm_i915_private *dev_priv = dev->dev_private;
1915 struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
1917 if (WARN_ON(pll == NULL))
1920 if (WARN_ON(pll->config.crtc_mask == 0))
1923 DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n",
1924 pll->name, pll->active, pll->on,
1925 crtc->base.base.id);
1927 if (pll->active++) {
1929 assert_shared_dpll_enabled(dev_priv, pll);
1934 intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
1936 DRM_DEBUG_KMS("enabling %s\n", pll->name);
1937 pll->enable(dev_priv, pll);
1941 static void intel_disable_shared_dpll(struct intel_crtc *crtc)
1943 struct drm_device *dev = crtc->base.dev;
1944 struct drm_i915_private *dev_priv = dev->dev_private;
1945 struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
1947 /* PCH only available on ILK+ */
1948 BUG_ON(INTEL_INFO(dev)->gen < 5);
1952 if (WARN_ON(!(pll->config.crtc_mask & (1 << drm_crtc_index(&crtc->base)))))
1955 DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
1956 pll->name, pll->active, pll->on,
1957 crtc->base.base.id);
1959 if (WARN_ON(pll->active == 0)) {
1960 assert_shared_dpll_disabled(dev_priv, pll);
1964 assert_shared_dpll_enabled(dev_priv, pll);
1969 DRM_DEBUG_KMS("disabling %s\n", pll->name);
1970 pll->disable(dev_priv, pll);
1973 intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS);
1976 static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1979 struct drm_device *dev = dev_priv->dev;
1980 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
1981 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1982 uint32_t reg, val, pipeconf_val;
1984 /* PCH only available on ILK+ */
1985 BUG_ON(!HAS_PCH_SPLIT(dev));
1987 /* Make sure PCH DPLL is enabled */
1988 assert_shared_dpll_enabled(dev_priv,
1989 intel_crtc_to_shared_dpll(intel_crtc));
1991 /* FDI must be feeding us bits for PCH ports */
1992 assert_fdi_tx_enabled(dev_priv, pipe);
1993 assert_fdi_rx_enabled(dev_priv, pipe);
1995 if (HAS_PCH_CPT(dev)) {
1996 /* Workaround: Set the timing override bit before enabling the
1997 * pch transcoder. */
1998 reg = TRANS_CHICKEN2(pipe);
1999 val = I915_READ(reg);
2000 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
2001 I915_WRITE(reg, val);
2004 reg = PCH_TRANSCONF(pipe);
2005 val = I915_READ(reg);
2006 pipeconf_val = I915_READ(PIPECONF(pipe));
2008 if (HAS_PCH_IBX(dev_priv->dev)) {
2010 * Make the BPC in transcoder be consistent with
2011 * that in pipeconf reg. For HDMI we must use 8bpc
2012 * here for both 8bpc and 12bpc.
2014 val &= ~PIPECONF_BPC_MASK;
2015 if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_HDMI))
2016 val |= PIPECONF_8BPC;
2018 val |= pipeconf_val & PIPECONF_BPC_MASK;
2021 val &= ~TRANS_INTERLACE_MASK;
2022 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
2023 if (HAS_PCH_IBX(dev_priv->dev) &&
2024 intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO))
2025 val |= TRANS_LEGACY_INTERLACED_ILK;
2027 val |= TRANS_INTERLACED;
2029 val |= TRANS_PROGRESSIVE;
2031 I915_WRITE(reg, val | TRANS_ENABLE);
2032 if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
2033 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
2036 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
2037 enum transcoder cpu_transcoder)
2039 u32 val, pipeconf_val;
2041 /* PCH only available on ILK+ */
2042 BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev));
2044 /* FDI must be feeding us bits for PCH ports */
2045 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
2046 assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
2048 /* Workaround: set timing override bit. */
2049 val = I915_READ(_TRANSA_CHICKEN2);
2050 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
2051 I915_WRITE(_TRANSA_CHICKEN2, val);
2054 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
2056 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
2057 PIPECONF_INTERLACED_ILK)
2058 val |= TRANS_INTERLACED;
2060 val |= TRANS_PROGRESSIVE;
2062 I915_WRITE(LPT_TRANSCONF, val);
2063 if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100))
2064 DRM_ERROR("Failed to enable PCH transcoder\n");
2067 static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
2070 struct drm_device *dev = dev_priv->dev;
2073 /* FDI relies on the transcoder */
2074 assert_fdi_tx_disabled(dev_priv, pipe);
2075 assert_fdi_rx_disabled(dev_priv, pipe);
2077 /* Ports must be off as well */
2078 assert_pch_ports_disabled(dev_priv, pipe);
2080 reg = PCH_TRANSCONF(pipe);
2081 val = I915_READ(reg);
2082 val &= ~TRANS_ENABLE;
2083 I915_WRITE(reg, val);
2084 /* wait for PCH transcoder off, transcoder state */
2085 if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
2086 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
2088 if (!HAS_PCH_IBX(dev)) {
2089 /* Workaround: Clear the timing override chicken bit again. */
2090 reg = TRANS_CHICKEN2(pipe);
2091 val = I915_READ(reg);
2092 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
2093 I915_WRITE(reg, val);
2097 static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
2101 val = I915_READ(LPT_TRANSCONF);
2102 val &= ~TRANS_ENABLE;
2103 I915_WRITE(LPT_TRANSCONF, val);
2104 /* wait for PCH transcoder off, transcoder state */
2105 if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50))
2106 DRM_ERROR("Failed to disable PCH transcoder\n");
2108 /* Workaround: clear timing override bit. */
2109 val = I915_READ(_TRANSA_CHICKEN2);
2110 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
2111 I915_WRITE(_TRANSA_CHICKEN2, val);
2115 * intel_enable_pipe - enable a pipe, asserting requirements
2116 * @crtc: crtc responsible for the pipe
2118 * Enable @crtc's pipe, making sure that various hardware specific requirements
2119 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
2121 static void intel_enable_pipe(struct intel_crtc *crtc)
2123 struct drm_device *dev = crtc->base.dev;
2124 struct drm_i915_private *dev_priv = dev->dev_private;
2125 enum pipe pipe = crtc->pipe;
2126 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
2128 enum pipe pch_transcoder;
2132 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
2134 assert_planes_disabled(dev_priv, pipe);
2135 assert_cursor_disabled(dev_priv, pipe);
2136 assert_sprites_disabled(dev_priv, pipe);
2138 if (HAS_PCH_LPT(dev_priv->dev))
2139 pch_transcoder = TRANSCODER_A;
2141 pch_transcoder = pipe;
2144 * A pipe without a PLL won't actually be able to drive bits from
2145 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
2148 if (HAS_GMCH_DISPLAY(dev_priv->dev))
2149 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI))
2150 assert_dsi_pll_enabled(dev_priv);
2152 assert_pll_enabled(dev_priv, pipe);
2154 if (crtc->config->has_pch_encoder) {
2155 /* if driving the PCH, we need FDI enabled */
2156 assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
2157 assert_fdi_tx_pll_enabled(dev_priv,
2158 (enum pipe) cpu_transcoder);
2160 /* FIXME: assert CPU port conditions for SNB+ */
2163 reg = PIPECONF(cpu_transcoder);
2164 val = I915_READ(reg);
2165 if (val & PIPECONF_ENABLE) {
2166 WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
2167 (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)));
2171 I915_WRITE(reg, val | PIPECONF_ENABLE);
2176 * intel_disable_pipe - disable a pipe, asserting requirements
2177 * @crtc: crtc whose pipes is to be disabled
2179 * Disable the pipe of @crtc, making sure that various hardware
2180 * specific requirements are met, if applicable, e.g. plane
2181 * disabled, panel fitter off, etc.
2183 * Will wait until the pipe has shut down before returning.
2185 static void intel_disable_pipe(struct intel_crtc *crtc)
2187 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
2188 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
2189 enum pipe pipe = crtc->pipe;
2193 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
2196 * Make sure planes won't keep trying to pump pixels to us,
2197 * or we might hang the display.
2199 assert_planes_disabled(dev_priv, pipe);
2200 assert_cursor_disabled(dev_priv, pipe);
2201 assert_sprites_disabled(dev_priv, pipe);
2203 reg = PIPECONF(cpu_transcoder);
2204 val = I915_READ(reg);
2205 if ((val & PIPECONF_ENABLE) == 0)
2209 * Double wide has implications for planes
2210 * so best keep it disabled when not needed.
2212 if (crtc->config->double_wide)
2213 val &= ~PIPECONF_DOUBLE_WIDE;
2215 /* Don't disable pipe or pipe PLLs if needed */
2216 if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) &&
2217 !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
2218 val &= ~PIPECONF_ENABLE;
2220 I915_WRITE(reg, val);
2221 if ((val & PIPECONF_ENABLE) == 0)
2222 intel_wait_for_pipe_off(crtc);
2225 static bool need_vtd_wa(struct drm_device *dev)
2227 #ifdef CONFIG_INTEL_IOMMU
2228 if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped)
2235 intel_tile_height(struct drm_device *dev, uint32_t pixel_format,
2236 uint64_t fb_format_modifier)
2238 unsigned int tile_height;
2239 uint32_t pixel_bytes;
2241 switch (fb_format_modifier) {
2242 case DRM_FORMAT_MOD_NONE:
2245 case I915_FORMAT_MOD_X_TILED:
2246 tile_height = IS_GEN2(dev) ? 16 : 8;
2248 case I915_FORMAT_MOD_Y_TILED:
2251 case I915_FORMAT_MOD_Yf_TILED:
2252 pixel_bytes = drm_format_plane_cpp(pixel_format, 0);
2253 switch (pixel_bytes) {
2267 "128-bit pixels are not supported for display!");
2273 MISSING_CASE(fb_format_modifier);
2282 intel_fb_align_height(struct drm_device *dev, unsigned int height,
2283 uint32_t pixel_format, uint64_t fb_format_modifier)
2285 return ALIGN(height, intel_tile_height(dev, pixel_format,
2286 fb_format_modifier));
2290 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, struct drm_framebuffer *fb,
2291 const struct drm_plane_state *plane_state)
2293 struct intel_rotation_info *info = &view->rotation_info;
2294 unsigned int tile_height, tile_pitch;
2296 *view = i915_ggtt_view_normal;
2301 if (!intel_rotation_90_or_270(plane_state->rotation))
2304 *view = i915_ggtt_view_rotated;
2306 info->height = fb->height;
2307 info->pixel_format = fb->pixel_format;
2308 info->pitch = fb->pitches[0];
2309 info->fb_modifier = fb->modifier[0];
2311 tile_height = intel_tile_height(fb->dev, fb->pixel_format,
2313 tile_pitch = PAGE_SIZE / tile_height;
2314 info->width_pages = DIV_ROUND_UP(fb->pitches[0], tile_pitch);
2315 info->height_pages = DIV_ROUND_UP(fb->height, tile_height);
2316 info->size = info->width_pages * info->height_pages * PAGE_SIZE;
2321 static unsigned int intel_linear_alignment(struct drm_i915_private *dev_priv)
2323 if (INTEL_INFO(dev_priv)->gen >= 9)
2325 else if (IS_BROADWATER(dev_priv) || IS_CRESTLINE(dev_priv) ||
2326 IS_VALLEYVIEW(dev_priv))
2328 else if (INTEL_INFO(dev_priv)->gen >= 4)
2335 intel_pin_and_fence_fb_obj(struct drm_plane *plane,
2336 struct drm_framebuffer *fb,
2337 const struct drm_plane_state *plane_state,
2338 struct intel_engine_cs *pipelined,
2339 struct drm_i915_gem_request **pipelined_request)
2341 struct drm_device *dev = fb->dev;
2342 struct drm_i915_private *dev_priv = dev->dev_private;
2343 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2344 struct i915_ggtt_view view;
2348 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2350 switch (fb->modifier[0]) {
2351 case DRM_FORMAT_MOD_NONE:
2352 alignment = intel_linear_alignment(dev_priv);
2354 case I915_FORMAT_MOD_X_TILED:
2355 if (INTEL_INFO(dev)->gen >= 9)
2356 alignment = 256 * 1024;
2358 /* pin() will align the object as required by fence */
2362 case I915_FORMAT_MOD_Y_TILED:
2363 case I915_FORMAT_MOD_Yf_TILED:
2364 if (WARN_ONCE(INTEL_INFO(dev)->gen < 9,
2365 "Y tiling bo slipped through, driver bug!\n"))
2367 alignment = 1 * 1024 * 1024;
2370 MISSING_CASE(fb->modifier[0]);
2374 ret = intel_fill_fb_ggtt_view(&view, fb, plane_state);
2378 /* Note that the w/a also requires 64 PTE of padding following the
2379 * bo. We currently fill all unused PTE with the shadow page and so
2380 * we should always have valid PTE following the scanout preventing
2383 if (need_vtd_wa(dev) && alignment < 256 * 1024)
2384 alignment = 256 * 1024;
2387 * Global gtt pte registers are special registers which actually forward
2388 * writes to a chunk of system memory. Which means that there is no risk
2389 * that the register values disappear as soon as we call
2390 * intel_runtime_pm_put(), so it is correct to wrap only the
2391 * pin/unpin/fence and not more.
2393 intel_runtime_pm_get(dev_priv);
2395 dev_priv->mm.interruptible = false;
2396 ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined,
2397 pipelined_request, &view);
2399 goto err_interruptible;
2401 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2402 * fence, whereas 965+ only requires a fence if using
2403 * framebuffer compression. For simplicity, we always install
2404 * a fence as the cost is not that onerous.
2406 ret = i915_gem_object_get_fence(obj);
2410 i915_gem_object_pin_fence(obj);
2412 dev_priv->mm.interruptible = true;
2413 intel_runtime_pm_put(dev_priv);
2417 i915_gem_object_unpin_from_display_plane(obj, &view);
2419 dev_priv->mm.interruptible = true;
2420 intel_runtime_pm_put(dev_priv);
2424 static void intel_unpin_fb_obj(struct drm_framebuffer *fb,
2425 const struct drm_plane_state *plane_state)
2427 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2428 struct i915_ggtt_view view;
2431 WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex));
2433 ret = intel_fill_fb_ggtt_view(&view, fb, plane_state);
2434 WARN_ONCE(ret, "Couldn't get view from plane state!");
2436 i915_gem_object_unpin_fence(obj);
2437 i915_gem_object_unpin_from_display_plane(obj, &view);
2440 /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
2441 * is assumed to be a power-of-two. */
2442 unsigned long intel_gen4_compute_page_offset(struct drm_i915_private *dev_priv,
2444 unsigned int tiling_mode,
2448 if (tiling_mode != I915_TILING_NONE) {
2449 unsigned int tile_rows, tiles;
2454 tiles = *x / (512/cpp);
2457 return tile_rows * pitch * 8 + tiles * 4096;
2459 unsigned int alignment = intel_linear_alignment(dev_priv) - 1;
2460 unsigned int offset;
2462 offset = *y * pitch + *x * cpp;
2463 *y = (offset & alignment) / pitch;
2464 *x = ((offset & alignment) - *y * pitch) / cpp;
2465 return offset & ~alignment;
2469 static int i9xx_format_to_fourcc(int format)
2472 case DISPPLANE_8BPP:
2473 return DRM_FORMAT_C8;
2474 case DISPPLANE_BGRX555:
2475 return DRM_FORMAT_XRGB1555;
2476 case DISPPLANE_BGRX565:
2477 return DRM_FORMAT_RGB565;
2479 case DISPPLANE_BGRX888:
2480 return DRM_FORMAT_XRGB8888;
2481 case DISPPLANE_RGBX888:
2482 return DRM_FORMAT_XBGR8888;
2483 case DISPPLANE_BGRX101010:
2484 return DRM_FORMAT_XRGB2101010;
2485 case DISPPLANE_RGBX101010:
2486 return DRM_FORMAT_XBGR2101010;
2490 static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
2493 case PLANE_CTL_FORMAT_RGB_565:
2494 return DRM_FORMAT_RGB565;
2496 case PLANE_CTL_FORMAT_XRGB_8888:
2499 return DRM_FORMAT_ABGR8888;
2501 return DRM_FORMAT_XBGR8888;
2504 return DRM_FORMAT_ARGB8888;
2506 return DRM_FORMAT_XRGB8888;
2508 case PLANE_CTL_FORMAT_XRGB_2101010:
2510 return DRM_FORMAT_XBGR2101010;
2512 return DRM_FORMAT_XRGB2101010;
2517 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2518 struct intel_initial_plane_config *plane_config)
2520 struct drm_device *dev = crtc->base.dev;
2521 struct drm_i915_gem_object *obj = NULL;
2522 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
2523 struct drm_framebuffer *fb = &plane_config->fb->base;
2524 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2525 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2528 size_aligned -= base_aligned;
2530 if (plane_config->size == 0)
2533 obj = i915_gem_object_create_stolen_for_preallocated(dev,
2540 obj->tiling_mode = plane_config->tiling;
2541 if (obj->tiling_mode == I915_TILING_X)
2542 obj->stride = fb->pitches[0];
2544 mode_cmd.pixel_format = fb->pixel_format;
2545 mode_cmd.width = fb->width;
2546 mode_cmd.height = fb->height;
2547 mode_cmd.pitches[0] = fb->pitches[0];
2548 mode_cmd.modifier[0] = fb->modifier[0];
2549 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
2551 mutex_lock(&dev->struct_mutex);
2552 if (intel_framebuffer_init(dev, to_intel_framebuffer(fb),
2554 DRM_DEBUG_KMS("intel fb init failed\n");
2557 mutex_unlock(&dev->struct_mutex);
2559 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
2563 drm_gem_object_unreference(&obj->base);
2564 mutex_unlock(&dev->struct_mutex);
2568 /* Update plane->state->fb to match plane->fb after driver-internal updates */
2570 update_state_fb(struct drm_plane *plane)
2572 if (plane->fb == plane->state->fb)
2575 if (plane->state->fb)
2576 drm_framebuffer_unreference(plane->state->fb);
2577 plane->state->fb = plane->fb;
2578 if (plane->state->fb)
2579 drm_framebuffer_reference(plane->state->fb);
2583 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2584 struct intel_initial_plane_config *plane_config)
2586 struct drm_device *dev = intel_crtc->base.dev;
2587 struct drm_i915_private *dev_priv = dev->dev_private;
2589 struct intel_crtc *i;
2590 struct drm_i915_gem_object *obj;
2591 struct drm_plane *primary = intel_crtc->base.primary;
2592 struct drm_plane_state *plane_state = primary->state;
2593 struct drm_framebuffer *fb;
2595 if (!plane_config->fb)
2598 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
2599 fb = &plane_config->fb->base;
2603 kfree(plane_config->fb);
2606 * Failed to alloc the obj, check to see if we should share
2607 * an fb with another CRTC instead
2609 for_each_crtc(dev, c) {
2610 i = to_intel_crtc(c);
2612 if (c == &intel_crtc->base)
2618 fb = c->primary->fb;
2622 obj = intel_fb_obj(fb);
2623 if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) {
2624 drm_framebuffer_reference(fb);
2632 plane_state->src_x = plane_state->src_y = 0;
2633 plane_state->src_w = fb->width << 16;
2634 plane_state->src_h = fb->height << 16;
2636 plane_state->crtc_x = plane_state->src_y = 0;
2637 plane_state->crtc_w = fb->width;
2638 plane_state->crtc_h = fb->height;
2640 obj = intel_fb_obj(fb);
2641 if (obj->tiling_mode != I915_TILING_NONE)
2642 dev_priv->preserve_bios_swizzle = true;
2644 drm_framebuffer_reference(fb);
2645 primary->fb = primary->state->fb = fb;
2646 primary->crtc = primary->state->crtc = &intel_crtc->base;
2647 intel_crtc->base.state->plane_mask |= (1 << drm_plane_index(primary));
2648 obj->frontbuffer_bits |= to_intel_plane(primary)->frontbuffer_bit;
2651 static void i9xx_update_primary_plane(struct drm_crtc *crtc,
2652 struct drm_framebuffer *fb,
2655 struct drm_device *dev = crtc->dev;
2656 struct drm_i915_private *dev_priv = dev->dev_private;
2657 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2658 struct drm_plane *primary = crtc->primary;
2659 bool visible = to_intel_plane_state(primary->state)->visible;
2660 struct drm_i915_gem_object *obj;
2661 int plane = intel_crtc->plane;
2662 unsigned long linear_offset;
2664 u32 reg = DSPCNTR(plane);
2667 if (!visible || !fb) {
2669 if (INTEL_INFO(dev)->gen >= 4)
2670 I915_WRITE(DSPSURF(plane), 0);
2672 I915_WRITE(DSPADDR(plane), 0);
2677 obj = intel_fb_obj(fb);
2678 if (WARN_ON(obj == NULL))
2681 pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
2683 dspcntr = DISPPLANE_GAMMA_ENABLE;
2685 dspcntr |= DISPLAY_PLANE_ENABLE;
2687 if (INTEL_INFO(dev)->gen < 4) {
2688 if (intel_crtc->pipe == PIPE_B)
2689 dspcntr |= DISPPLANE_SEL_PIPE_B;
2691 /* pipesrc and dspsize control the size that is scaled from,
2692 * which should always be the user's requested size.
2694 I915_WRITE(DSPSIZE(plane),
2695 ((intel_crtc->config->pipe_src_h - 1) << 16) |
2696 (intel_crtc->config->pipe_src_w - 1));
2697 I915_WRITE(DSPPOS(plane), 0);
2698 } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) {
2699 I915_WRITE(PRIMSIZE(plane),
2700 ((intel_crtc->config->pipe_src_h - 1) << 16) |
2701 (intel_crtc->config->pipe_src_w - 1));
2702 I915_WRITE(PRIMPOS(plane), 0);
2703 I915_WRITE(PRIMCNSTALPHA(plane), 0);
2706 switch (fb->pixel_format) {
2708 dspcntr |= DISPPLANE_8BPP;
2710 case DRM_FORMAT_XRGB1555:
2711 dspcntr |= DISPPLANE_BGRX555;
2713 case DRM_FORMAT_RGB565:
2714 dspcntr |= DISPPLANE_BGRX565;
2716 case DRM_FORMAT_XRGB8888:
2717 dspcntr |= DISPPLANE_BGRX888;
2719 case DRM_FORMAT_XBGR8888:
2720 dspcntr |= DISPPLANE_RGBX888;
2722 case DRM_FORMAT_XRGB2101010:
2723 dspcntr |= DISPPLANE_BGRX101010;
2725 case DRM_FORMAT_XBGR2101010:
2726 dspcntr |= DISPPLANE_RGBX101010;
2732 if (INTEL_INFO(dev)->gen >= 4 &&
2733 obj->tiling_mode != I915_TILING_NONE)
2734 dspcntr |= DISPPLANE_TILED;
2737 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
2739 linear_offset = y * fb->pitches[0] + x * pixel_size;
2741 if (INTEL_INFO(dev)->gen >= 4) {
2742 intel_crtc->dspaddr_offset =
2743 intel_gen4_compute_page_offset(dev_priv,
2744 &x, &y, obj->tiling_mode,
2747 linear_offset -= intel_crtc->dspaddr_offset;
2749 intel_crtc->dspaddr_offset = linear_offset;
2752 if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) {
2753 dspcntr |= DISPPLANE_ROTATE_180;
2755 x += (intel_crtc->config->pipe_src_w - 1);
2756 y += (intel_crtc->config->pipe_src_h - 1);
2758 /* Finding the last pixel of the last line of the display
2759 data and adding to linear_offset*/
2761 (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] +
2762 (intel_crtc->config->pipe_src_w - 1) * pixel_size;
2765 I915_WRITE(reg, dspcntr);
2767 I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
2768 if (INTEL_INFO(dev)->gen >= 4) {
2769 I915_WRITE(DSPSURF(plane),
2770 i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
2771 I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
2772 I915_WRITE(DSPLINOFF(plane), linear_offset);
2774 I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset);
2778 static void ironlake_update_primary_plane(struct drm_crtc *crtc,
2779 struct drm_framebuffer *fb,
2782 struct drm_device *dev = crtc->dev;
2783 struct drm_i915_private *dev_priv = dev->dev_private;
2784 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2785 struct drm_plane *primary = crtc->primary;
2786 bool visible = to_intel_plane_state(primary->state)->visible;
2787 struct drm_i915_gem_object *obj;
2788 int plane = intel_crtc->plane;
2789 unsigned long linear_offset;
2791 u32 reg = DSPCNTR(plane);
2794 if (!visible || !fb) {
2796 I915_WRITE(DSPSURF(plane), 0);
2801 obj = intel_fb_obj(fb);
2802 if (WARN_ON(obj == NULL))
2805 pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
2807 dspcntr = DISPPLANE_GAMMA_ENABLE;
2809 dspcntr |= DISPLAY_PLANE_ENABLE;
2811 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
2812 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
2814 switch (fb->pixel_format) {
2816 dspcntr |= DISPPLANE_8BPP;
2818 case DRM_FORMAT_RGB565:
2819 dspcntr |= DISPPLANE_BGRX565;
2821 case DRM_FORMAT_XRGB8888:
2822 dspcntr |= DISPPLANE_BGRX888;
2824 case DRM_FORMAT_XBGR8888:
2825 dspcntr |= DISPPLANE_RGBX888;
2827 case DRM_FORMAT_XRGB2101010:
2828 dspcntr |= DISPPLANE_BGRX101010;
2830 case DRM_FORMAT_XBGR2101010:
2831 dspcntr |= DISPPLANE_RGBX101010;
2837 if (obj->tiling_mode != I915_TILING_NONE)
2838 dspcntr |= DISPPLANE_TILED;
2840 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev))
2841 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
2843 linear_offset = y * fb->pitches[0] + x * pixel_size;
2844 intel_crtc->dspaddr_offset =
2845 intel_gen4_compute_page_offset(dev_priv,
2846 &x, &y, obj->tiling_mode,
2849 linear_offset -= intel_crtc->dspaddr_offset;
2850 if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) {
2851 dspcntr |= DISPPLANE_ROTATE_180;
2853 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
2854 x += (intel_crtc->config->pipe_src_w - 1);
2855 y += (intel_crtc->config->pipe_src_h - 1);
2857 /* Finding the last pixel of the last line of the display
2858 data and adding to linear_offset*/
2860 (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] +
2861 (intel_crtc->config->pipe_src_w - 1) * pixel_size;
2865 I915_WRITE(reg, dspcntr);
2867 I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
2868 I915_WRITE(DSPSURF(plane),
2869 i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
2870 if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
2871 I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
2873 I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
2874 I915_WRITE(DSPLINOFF(plane), linear_offset);
2879 u32 intel_fb_stride_alignment(struct drm_device *dev, uint64_t fb_modifier,
2880 uint32_t pixel_format)
2882 u32 bits_per_pixel = drm_format_plane_cpp(pixel_format, 0) * 8;
2885 * The stride is either expressed as a multiple of 64 bytes
2886 * chunks for linear buffers or in number of tiles for tiled
2889 switch (fb_modifier) {
2890 case DRM_FORMAT_MOD_NONE:
2892 case I915_FORMAT_MOD_X_TILED:
2893 if (INTEL_INFO(dev)->gen == 2)
2896 case I915_FORMAT_MOD_Y_TILED:
2897 /* No need to check for old gens and Y tiling since this is
2898 * about the display engine and those will be blocked before
2902 case I915_FORMAT_MOD_Yf_TILED:
2903 if (bits_per_pixel == 8)
2908 MISSING_CASE(fb_modifier);
2913 unsigned long intel_plane_obj_offset(struct intel_plane *intel_plane,
2914 struct drm_i915_gem_object *obj)
2916 const struct i915_ggtt_view *view = &i915_ggtt_view_normal;
2918 if (intel_rotation_90_or_270(intel_plane->base.state->rotation))
2919 view = &i915_ggtt_view_rotated;
2921 return i915_gem_obj_ggtt_offset_view(obj, view);
2924 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
2926 struct drm_device *dev = intel_crtc->base.dev;
2927 struct drm_i915_private *dev_priv = dev->dev_private;
2929 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
2930 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
2931 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
2932 DRM_DEBUG_KMS("CRTC:%d Disabled scaler id %u.%u\n",
2933 intel_crtc->base.base.id, intel_crtc->pipe, id);
2937 * This function detaches (aka. unbinds) unused scalers in hardware
2939 static void skl_detach_scalers(struct intel_crtc *intel_crtc)
2941 struct intel_crtc_scaler_state *scaler_state;
2944 scaler_state = &intel_crtc->config->scaler_state;
2946 /* loop through and disable scalers that aren't in use */
2947 for (i = 0; i < intel_crtc->num_scalers; i++) {
2948 if (!scaler_state->scalers[i].in_use)
2949 skl_detach_scaler(intel_crtc, i);
2953 u32 skl_plane_ctl_format(uint32_t pixel_format)
2955 switch (pixel_format) {
2957 return PLANE_CTL_FORMAT_INDEXED;
2958 case DRM_FORMAT_RGB565:
2959 return PLANE_CTL_FORMAT_RGB_565;
2960 case DRM_FORMAT_XBGR8888:
2961 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
2962 case DRM_FORMAT_XRGB8888:
2963 return PLANE_CTL_FORMAT_XRGB_8888;
2965 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
2966 * to be already pre-multiplied. We need to add a knob (or a different
2967 * DRM_FORMAT) for user-space to configure that.
2969 case DRM_FORMAT_ABGR8888:
2970 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX |
2971 PLANE_CTL_ALPHA_SW_PREMULTIPLY;
2972 case DRM_FORMAT_ARGB8888:
2973 return PLANE_CTL_FORMAT_XRGB_8888 |
2974 PLANE_CTL_ALPHA_SW_PREMULTIPLY;
2975 case DRM_FORMAT_XRGB2101010:
2976 return PLANE_CTL_FORMAT_XRGB_2101010;
2977 case DRM_FORMAT_XBGR2101010:
2978 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
2979 case DRM_FORMAT_YUYV:
2980 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
2981 case DRM_FORMAT_YVYU:
2982 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
2983 case DRM_FORMAT_UYVY:
2984 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
2985 case DRM_FORMAT_VYUY:
2986 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
2988 MISSING_CASE(pixel_format);
2994 u32 skl_plane_ctl_tiling(uint64_t fb_modifier)
2996 switch (fb_modifier) {
2997 case DRM_FORMAT_MOD_NONE:
2999 case I915_FORMAT_MOD_X_TILED:
3000 return PLANE_CTL_TILED_X;
3001 case I915_FORMAT_MOD_Y_TILED:
3002 return PLANE_CTL_TILED_Y;
3003 case I915_FORMAT_MOD_Yf_TILED:
3004 return PLANE_CTL_TILED_YF;
3006 MISSING_CASE(fb_modifier);
3012 u32 skl_plane_ctl_rotation(unsigned int rotation)
3015 case BIT(DRM_ROTATE_0):
3018 * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr
3019 * while i915 HW rotation is clockwise, thats why this swapping.
3021 case BIT(DRM_ROTATE_90):
3022 return PLANE_CTL_ROTATE_270;
3023 case BIT(DRM_ROTATE_180):
3024 return PLANE_CTL_ROTATE_180;
3025 case BIT(DRM_ROTATE_270):
3026 return PLANE_CTL_ROTATE_90;
3028 MISSING_CASE(rotation);
3034 static void skylake_update_primary_plane(struct drm_crtc *crtc,
3035 struct drm_framebuffer *fb,
3038 struct drm_device *dev = crtc->dev;
3039 struct drm_i915_private *dev_priv = dev->dev_private;
3040 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3041 struct drm_plane *plane = crtc->primary;
3042 bool visible = to_intel_plane_state(plane->state)->visible;
3043 struct drm_i915_gem_object *obj;
3044 int pipe = intel_crtc->pipe;
3045 u32 plane_ctl, stride_div, stride;
3046 u32 tile_height, plane_offset, plane_size;
3047 unsigned int rotation;
3048 int x_offset, y_offset;
3049 unsigned long surf_addr;
3050 struct intel_crtc_state *crtc_state = intel_crtc->config;
3051 struct intel_plane_state *plane_state;
3052 int src_x = 0, src_y = 0, src_w = 0, src_h = 0;
3053 int dst_x = 0, dst_y = 0, dst_w = 0, dst_h = 0;
3056 plane_state = to_intel_plane_state(plane->state);
3058 if (!visible || !fb) {
3059 I915_WRITE(PLANE_CTL(pipe, 0), 0);
3060 I915_WRITE(PLANE_SURF(pipe, 0), 0);
3061 POSTING_READ(PLANE_CTL(pipe, 0));
3065 plane_ctl = PLANE_CTL_ENABLE |
3066 PLANE_CTL_PIPE_GAMMA_ENABLE |
3067 PLANE_CTL_PIPE_CSC_ENABLE;
3069 plane_ctl |= skl_plane_ctl_format(fb->pixel_format);
3070 plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]);
3071 plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
3073 rotation = plane->state->rotation;
3074 plane_ctl |= skl_plane_ctl_rotation(rotation);
3076 obj = intel_fb_obj(fb);
3077 stride_div = intel_fb_stride_alignment(dev, fb->modifier[0],
3079 surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj);
3082 * FIXME: intel_plane_state->src, dst aren't set when transitional
3083 * update_plane helpers are called from legacy paths.
3084 * Once full atomic crtc is available, below check can be avoided.
3086 if (drm_rect_width(&plane_state->src)) {
3087 scaler_id = plane_state->scaler_id;
3088 src_x = plane_state->src.x1 >> 16;
3089 src_y = plane_state->src.y1 >> 16;
3090 src_w = drm_rect_width(&plane_state->src) >> 16;
3091 src_h = drm_rect_height(&plane_state->src) >> 16;
3092 dst_x = plane_state->dst.x1;
3093 dst_y = plane_state->dst.y1;
3094 dst_w = drm_rect_width(&plane_state->dst);
3095 dst_h = drm_rect_height(&plane_state->dst);
3097 WARN_ON(x != src_x || y != src_y);
3099 src_w = intel_crtc->config->pipe_src_w;
3100 src_h = intel_crtc->config->pipe_src_h;
3103 if (intel_rotation_90_or_270(rotation)) {
3104 /* stride = Surface height in tiles */
3105 tile_height = intel_tile_height(dev, fb->pixel_format,
3107 stride = DIV_ROUND_UP(fb->height, tile_height);
3108 x_offset = stride * tile_height - y - src_h;
3110 plane_size = (src_w - 1) << 16 | (src_h - 1);
3112 stride = fb->pitches[0] / stride_div;
3115 plane_size = (src_h - 1) << 16 | (src_w - 1);
3117 plane_offset = y_offset << 16 | x_offset;
3119 I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl);
3120 I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset);
3121 I915_WRITE(PLANE_SIZE(pipe, 0), plane_size);
3122 I915_WRITE(PLANE_STRIDE(pipe, 0), stride);
3124 if (scaler_id >= 0) {
3125 uint32_t ps_ctrl = 0;
3127 WARN_ON(!dst_w || !dst_h);
3128 ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(0) |
3129 crtc_state->scaler_state.scalers[scaler_id].mode;
3130 I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl);
3131 I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0);
3132 I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y);
3133 I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h);
3134 I915_WRITE(PLANE_POS(pipe, 0), 0);
3136 I915_WRITE(PLANE_POS(pipe, 0), (dst_y << 16) | dst_x);
3139 I915_WRITE(PLANE_SURF(pipe, 0), surf_addr);
3141 POSTING_READ(PLANE_SURF(pipe, 0));
3144 /* Assume fb object is pinned & idle & fenced and just update base pointers */
3146 intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
3147 int x, int y, enum mode_set_atomic state)
3149 struct drm_device *dev = crtc->dev;
3150 struct drm_i915_private *dev_priv = dev->dev_private;
3152 if (dev_priv->fbc.disable_fbc)
3153 dev_priv->fbc.disable_fbc(dev_priv);
3155 dev_priv->display.update_primary_plane(crtc, fb, x, y);
3160 static void intel_complete_page_flips(struct drm_device *dev)
3162 struct drm_crtc *crtc;
3164 for_each_crtc(dev, crtc) {
3165 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3166 enum plane plane = intel_crtc->plane;
3168 intel_prepare_page_flip(dev, plane);
3169 intel_finish_page_flip_plane(dev, plane);
3173 static void intel_update_primary_planes(struct drm_device *dev)
3175 struct drm_i915_private *dev_priv = dev->dev_private;
3176 struct drm_crtc *crtc;
3178 for_each_crtc(dev, crtc) {
3179 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3181 drm_modeset_lock(&crtc->mutex, NULL);
3183 * FIXME: Once we have proper support for primary planes (and
3184 * disabling them without disabling the entire crtc) allow again
3185 * a NULL crtc->primary->fb.
3187 if (intel_crtc->active && crtc->primary->fb)
3188 dev_priv->display.update_primary_plane(crtc,
3192 drm_modeset_unlock(&crtc->mutex);
3196 void intel_prepare_reset(struct drm_device *dev)
3198 /* no reset support for gen2 */
3202 /* reset doesn't touch the display */
3203 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
3206 drm_modeset_lock_all(dev);
3208 * Disabling the crtcs gracefully seems nicer. Also the
3209 * g33 docs say we should at least disable all the planes.
3211 intel_display_suspend(dev);
3214 void intel_finish_reset(struct drm_device *dev)
3216 struct drm_i915_private *dev_priv = to_i915(dev);
3219 * Flips in the rings will be nuked by the reset,
3220 * so complete all pending flips so that user space
3221 * will get its events and not get stuck.
3223 intel_complete_page_flips(dev);
3225 /* no reset support for gen2 */
3229 /* reset doesn't touch the display */
3230 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) {
3232 * Flips in the rings have been nuked by the reset,
3233 * so update the base address of all primary
3234 * planes to the the last fb to make sure we're
3235 * showing the correct fb after a reset.
3237 intel_update_primary_planes(dev);
3242 * The display has been reset as well,
3243 * so need a full re-initialization.
3245 intel_runtime_pm_disable_interrupts(dev_priv);
3246 intel_runtime_pm_enable_interrupts(dev_priv);
3248 intel_modeset_init_hw(dev);
3250 spin_lock_irq(&dev_priv->irq_lock);
3251 if (dev_priv->display.hpd_irq_setup)
3252 dev_priv->display.hpd_irq_setup(dev);
3253 spin_unlock_irq(&dev_priv->irq_lock);
3255 intel_display_resume(dev);
3257 intel_hpd_init(dev_priv);
3259 drm_modeset_unlock_all(dev);
3263 intel_finish_fb(struct drm_framebuffer *old_fb)
3265 struct drm_i915_gem_object *obj = intel_fb_obj(old_fb);
3266 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
3267 bool was_interruptible = dev_priv->mm.interruptible;
3270 /* Big Hammer, we also need to ensure that any pending
3271 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
3272 * current scanout is retired before unpinning the old
3273 * framebuffer. Note that we rely on userspace rendering
3274 * into the buffer attached to the pipe they are waiting
3275 * on. If not, userspace generates a GPU hang with IPEHR
3276 * point to the MI_WAIT_FOR_EVENT.
3278 * This should only fail upon a hung GPU, in which case we
3279 * can safely continue.
3281 dev_priv->mm.interruptible = false;
3282 ret = i915_gem_object_wait_rendering(obj, true);
3283 dev_priv->mm.interruptible = was_interruptible;
3288 static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
3290 struct drm_device *dev = crtc->dev;
3291 struct drm_i915_private *dev_priv = dev->dev_private;
3292 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3295 if (i915_reset_in_progress(&dev_priv->gpu_error) ||
3296 intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
3299 spin_lock_irq(&dev->event_lock);
3300 pending = to_intel_crtc(crtc)->unpin_work != NULL;
3301 spin_unlock_irq(&dev->event_lock);
3306 static void intel_update_pipe_size(struct intel_crtc *crtc)
3308 struct drm_device *dev = crtc->base.dev;
3309 struct drm_i915_private *dev_priv = dev->dev_private;
3310 const struct drm_display_mode *adjusted_mode;
3316 * Update pipe size and adjust fitter if needed: the reason for this is
3317 * that in compute_mode_changes we check the native mode (not the pfit
3318 * mode) to see if we can flip rather than do a full mode set. In the
3319 * fastboot case, we'll flip, but if we don't update the pipesrc and
3320 * pfit state, we'll end up with a big fb scanned out into the wrong
3323 * To fix this properly, we need to hoist the checks up into
3324 * compute_mode_changes (or above), check the actual pfit state and
3325 * whether the platform allows pfit disable with pipe active, and only
3326 * then update the pipesrc and pfit state, even on the flip path.
3329 adjusted_mode = &crtc->config->base.adjusted_mode;
3331 I915_WRITE(PIPESRC(crtc->pipe),
3332 ((adjusted_mode->crtc_hdisplay - 1) << 16) |
3333 (adjusted_mode->crtc_vdisplay - 1));
3334 if (!crtc->config->pch_pfit.enabled &&
3335 (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
3336 intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
3337 I915_WRITE(PF_CTL(crtc->pipe), 0);
3338 I915_WRITE(PF_WIN_POS(crtc->pipe), 0);
3339 I915_WRITE(PF_WIN_SZ(crtc->pipe), 0);
3341 crtc->config->pipe_src_w = adjusted_mode->crtc_hdisplay;
3342 crtc->config->pipe_src_h = adjusted_mode->crtc_vdisplay;
3345 static void intel_fdi_normal_train(struct drm_crtc *crtc)
3347 struct drm_device *dev = crtc->dev;
3348 struct drm_i915_private *dev_priv = dev->dev_private;
3349 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3350 int pipe = intel_crtc->pipe;
3353 /* enable normal train */
3354 reg = FDI_TX_CTL(pipe);
3355 temp = I915_READ(reg);
3356 if (IS_IVYBRIDGE(dev)) {
3357 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
3358 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
3360 temp &= ~FDI_LINK_TRAIN_NONE;
3361 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
3363 I915_WRITE(reg, temp);
3365 reg = FDI_RX_CTL(pipe);
3366 temp = I915_READ(reg);
3367 if (HAS_PCH_CPT(dev)) {
3368 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3369 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
3371 temp &= ~FDI_LINK_TRAIN_NONE;
3372 temp |= FDI_LINK_TRAIN_NONE;
3374 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
3376 /* wait one idle pattern time */
3380 /* IVB wants error correction enabled */
3381 if (IS_IVYBRIDGE(dev))
3382 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
3383 FDI_FE_ERRC_ENABLE);
3386 /* The FDI link training functions for ILK/Ibexpeak. */
3387 static void ironlake_fdi_link_train(struct drm_crtc *crtc)
3389 struct drm_device *dev = crtc->dev;
3390 struct drm_i915_private *dev_priv = dev->dev_private;
3391 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3392 int pipe = intel_crtc->pipe;
3393 u32 reg, temp, tries;
3395 /* FDI needs bits from pipe first */
3396 assert_pipe_enabled(dev_priv, pipe);
3398 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3400 reg = FDI_RX_IMR(pipe);
3401 temp = I915_READ(reg);
3402 temp &= ~FDI_RX_SYMBOL_LOCK;
3403 temp &= ~FDI_RX_BIT_LOCK;
3404 I915_WRITE(reg, temp);
3408 /* enable CPU FDI TX and PCH FDI RX */
3409 reg = FDI_TX_CTL(pipe);
3410 temp = I915_READ(reg);
3411 temp &= ~FDI_DP_PORT_WIDTH_MASK;
3412 temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
3413 temp &= ~FDI_LINK_TRAIN_NONE;
3414 temp |= FDI_LINK_TRAIN_PATTERN_1;
3415 I915_WRITE(reg, temp | FDI_TX_ENABLE);
3417 reg = FDI_RX_CTL(pipe);
3418 temp = I915_READ(reg);
3419 temp &= ~FDI_LINK_TRAIN_NONE;
3420 temp |= FDI_LINK_TRAIN_PATTERN_1;
3421 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3426 /* Ironlake workaround, enable clock pointer after FDI enable*/
3427 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
3428 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
3429 FDI_RX_PHASE_SYNC_POINTER_EN);
3431 reg = FDI_RX_IIR(pipe);
3432 for (tries = 0; tries < 5; tries++) {
3433 temp = I915_READ(reg);
3434 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3436 if ((temp & FDI_RX_BIT_LOCK)) {
3437 DRM_DEBUG_KMS("FDI train 1 done.\n");
3438 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
3443 DRM_ERROR("FDI train 1 fail!\n");
3446 reg = FDI_TX_CTL(pipe);
3447 temp = I915_READ(reg);
3448 temp &= ~FDI_LINK_TRAIN_NONE;
3449 temp |= FDI_LINK_TRAIN_PATTERN_2;
3450 I915_WRITE(reg, temp);
3452 reg = FDI_RX_CTL(pipe);
3453 temp = I915_READ(reg);
3454 temp &= ~FDI_LINK_TRAIN_NONE;
3455 temp |= FDI_LINK_TRAIN_PATTERN_2;
3456 I915_WRITE(reg, temp);
3461 reg = FDI_RX_IIR(pipe);
3462 for (tries = 0; tries < 5; tries++) {
3463 temp = I915_READ(reg);
3464 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3466 if (temp & FDI_RX_SYMBOL_LOCK) {
3467 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
3468 DRM_DEBUG_KMS("FDI train 2 done.\n");
3473 DRM_ERROR("FDI train 2 fail!\n");
3475 DRM_DEBUG_KMS("FDI train done\n");
3479 static const int snb_b_fdi_train_param[] = {
3480 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
3481 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
3482 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
3483 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
3486 /* The FDI link training functions for SNB/Cougarpoint. */
3487 static void gen6_fdi_link_train(struct drm_crtc *crtc)
3489 struct drm_device *dev = crtc->dev;
3490 struct drm_i915_private *dev_priv = dev->dev_private;
3491 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3492 int pipe = intel_crtc->pipe;
3493 u32 reg, temp, i, retry;
3495 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3497 reg = FDI_RX_IMR(pipe);
3498 temp = I915_READ(reg);
3499 temp &= ~FDI_RX_SYMBOL_LOCK;
3500 temp &= ~FDI_RX_BIT_LOCK;
3501 I915_WRITE(reg, temp);
3506 /* enable CPU FDI TX and PCH FDI RX */
3507 reg = FDI_TX_CTL(pipe);
3508 temp = I915_READ(reg);
3509 temp &= ~FDI_DP_PORT_WIDTH_MASK;
3510 temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
3511 temp &= ~FDI_LINK_TRAIN_NONE;
3512 temp |= FDI_LINK_TRAIN_PATTERN_1;
3513 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
3515 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
3516 I915_WRITE(reg, temp | FDI_TX_ENABLE);
3518 I915_WRITE(FDI_RX_MISC(pipe),
3519 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
3521 reg = FDI_RX_CTL(pipe);
3522 temp = I915_READ(reg);
3523 if (HAS_PCH_CPT(dev)) {
3524 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3525 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
3527 temp &= ~FDI_LINK_TRAIN_NONE;
3528 temp |= FDI_LINK_TRAIN_PATTERN_1;
3530 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3535 for (i = 0; i < 4; i++) {
3536 reg = FDI_TX_CTL(pipe);
3537 temp = I915_READ(reg);
3538 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
3539 temp |= snb_b_fdi_train_param[i];
3540 I915_WRITE(reg, temp);
3545 for (retry = 0; retry < 5; retry++) {
3546 reg = FDI_RX_IIR(pipe);
3547 temp = I915_READ(reg);
3548 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3549 if (temp & FDI_RX_BIT_LOCK) {
3550 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
3551 DRM_DEBUG_KMS("FDI train 1 done.\n");
3560 DRM_ERROR("FDI train 1 fail!\n");
3563 reg = FDI_TX_CTL(pipe);
3564 temp = I915_READ(reg);
3565 temp &= ~FDI_LINK_TRAIN_NONE;
3566 temp |= FDI_LINK_TRAIN_PATTERN_2;
3568 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
3570 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
3572 I915_WRITE(reg, temp);
3574 reg = FDI_RX_CTL(pipe);
3575 temp = I915_READ(reg);
3576 if (HAS_PCH_CPT(dev)) {
3577 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3578 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
3580 temp &= ~FDI_LINK_TRAIN_NONE;
3581 temp |= FDI_LINK_TRAIN_PATTERN_2;
3583 I915_WRITE(reg, temp);
3588 for (i = 0; i < 4; i++) {
3589 reg = FDI_TX_CTL(pipe);
3590 temp = I915_READ(reg);
3591 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
3592 temp |= snb_b_fdi_train_param[i];
3593 I915_WRITE(reg, temp);
3598 for (retry = 0; retry < 5; retry++) {
3599 reg = FDI_RX_IIR(pipe);
3600 temp = I915_READ(reg);
3601 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3602 if (temp & FDI_RX_SYMBOL_LOCK) {
3603 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
3604 DRM_DEBUG_KMS("FDI train 2 done.\n");
3613 DRM_ERROR("FDI train 2 fail!\n");
3615 DRM_DEBUG_KMS("FDI train done.\n");
3618 /* Manual link training for Ivy Bridge A0 parts */
3619 static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
3621 struct drm_device *dev = crtc->dev;
3622 struct drm_i915_private *dev_priv = dev->dev_private;
3623 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3624 int pipe = intel_crtc->pipe;
3625 u32 reg, temp, i, j;
3627 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3629 reg = FDI_RX_IMR(pipe);
3630 temp = I915_READ(reg);
3631 temp &= ~FDI_RX_SYMBOL_LOCK;
3632 temp &= ~FDI_RX_BIT_LOCK;
3633 I915_WRITE(reg, temp);
3638 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3639 I915_READ(FDI_RX_IIR(pipe)));
3641 /* Try each vswing and preemphasis setting twice before moving on */
3642 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
3643 /* disable first in case we need to retry */
3644 reg = FDI_TX_CTL(pipe);
3645 temp = I915_READ(reg);
3646 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
3647 temp &= ~FDI_TX_ENABLE;
3648 I915_WRITE(reg, temp);
3650 reg = FDI_RX_CTL(pipe);
3651 temp = I915_READ(reg);
3652 temp &= ~FDI_LINK_TRAIN_AUTO;
3653 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3654 temp &= ~FDI_RX_ENABLE;
3655 I915_WRITE(reg, temp);
3657 /* enable CPU FDI TX and PCH FDI RX */
3658 reg = FDI_TX_CTL(pipe);
3659 temp = I915_READ(reg);
3660 temp &= ~FDI_DP_PORT_WIDTH_MASK;
3661 temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
3662 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
3663 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
3664 temp |= snb_b_fdi_train_param[j/2];
3665 temp |= FDI_COMPOSITE_SYNC;
3666 I915_WRITE(reg, temp | FDI_TX_ENABLE);
3668 I915_WRITE(FDI_RX_MISC(pipe),
3669 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
3671 reg = FDI_RX_CTL(pipe);
3672 temp = I915_READ(reg);
3673 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
3674 temp |= FDI_COMPOSITE_SYNC;
3675 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3678 udelay(1); /* should be 0.5us */
3680 for (i = 0; i < 4; i++) {
3681 reg = FDI_RX_IIR(pipe);
3682 temp = I915_READ(reg);
3683 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3685 if (temp & FDI_RX_BIT_LOCK ||
3686 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
3687 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
3688 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3692 udelay(1); /* should be 0.5us */
3695 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
3700 reg = FDI_TX_CTL(pipe);
3701 temp = I915_READ(reg);
3702 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
3703 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
3704 I915_WRITE(reg, temp);
3706 reg = FDI_RX_CTL(pipe);
3707 temp = I915_READ(reg);
3708 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3709 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
3710 I915_WRITE(reg, temp);
3713 udelay(2); /* should be 1.5us */
3715 for (i = 0; i < 4; i++) {
3716 reg = FDI_RX_IIR(pipe);
3717 temp = I915_READ(reg);
3718 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3720 if (temp & FDI_RX_SYMBOL_LOCK ||
3721 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
3722 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
3723 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
3727 udelay(2); /* should be 1.5us */
3730 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
3734 DRM_DEBUG_KMS("FDI train done.\n");
3737 static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
3739 struct drm_device *dev = intel_crtc->base.dev;
3740 struct drm_i915_private *dev_priv = dev->dev_private;
3741 int pipe = intel_crtc->pipe;
3745 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
3746 reg = FDI_RX_CTL(pipe);
3747 temp = I915_READ(reg);
3748 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
3749 temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
3750 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
3751 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
3756 /* Switch from Rawclk to PCDclk */
3757 temp = I915_READ(reg);
3758 I915_WRITE(reg, temp | FDI_PCDCLK);
3763 /* Enable CPU FDI TX PLL, always on for Ironlake */
3764 reg = FDI_TX_CTL(pipe);
3765 temp = I915_READ(reg);
3766 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
3767 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
3774 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
3776 struct drm_device *dev = intel_crtc->base.dev;
3777 struct drm_i915_private *dev_priv = dev->dev_private;
3778 int pipe = intel_crtc->pipe;
3781 /* Switch from PCDclk to Rawclk */
3782 reg = FDI_RX_CTL(pipe);
3783 temp = I915_READ(reg);
3784 I915_WRITE(reg, temp & ~FDI_PCDCLK);
3786 /* Disable CPU FDI TX PLL */
3787 reg = FDI_TX_CTL(pipe);
3788 temp = I915_READ(reg);
3789 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
3794 reg = FDI_RX_CTL(pipe);
3795 temp = I915_READ(reg);
3796 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
3798 /* Wait for the clocks to turn off. */
3803 static void ironlake_fdi_disable(struct drm_crtc *crtc)
3805 struct drm_device *dev = crtc->dev;
3806 struct drm_i915_private *dev_priv = dev->dev_private;
3807 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3808 int pipe = intel_crtc->pipe;
3811 /* disable CPU FDI tx and PCH FDI rx */
3812 reg = FDI_TX_CTL(pipe);
3813 temp = I915_READ(reg);
3814 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
3817 reg = FDI_RX_CTL(pipe);
3818 temp = I915_READ(reg);
3819 temp &= ~(0x7 << 16);
3820 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
3821 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
3826 /* Ironlake workaround, disable clock pointer after downing FDI */
3827 if (HAS_PCH_IBX(dev))
3828 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
3830 /* still set train pattern 1 */
3831 reg = FDI_TX_CTL(pipe);
3832 temp = I915_READ(reg);
3833 temp &= ~FDI_LINK_TRAIN_NONE;
3834 temp |= FDI_LINK_TRAIN_PATTERN_1;
3835 I915_WRITE(reg, temp);
3837 reg = FDI_RX_CTL(pipe);
3838 temp = I915_READ(reg);
3839 if (HAS_PCH_CPT(dev)) {
3840 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3841 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
3843 temp &= ~FDI_LINK_TRAIN_NONE;
3844 temp |= FDI_LINK_TRAIN_PATTERN_1;
3846 /* BPC in FDI rx is consistent with that in PIPECONF */
3847 temp &= ~(0x07 << 16);
3848 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
3849 I915_WRITE(reg, temp);
3855 bool intel_has_pending_fb_unpin(struct drm_device *dev)
3857 struct intel_crtc *crtc;
3859 /* Note that we don't need to be called with mode_config.lock here
3860 * as our list of CRTC objects is static for the lifetime of the
3861 * device and so cannot disappear as we iterate. Similarly, we can
3862 * happily treat the predicates as racy, atomic checks as userspace
3863 * cannot claim and pin a new fb without at least acquring the
3864 * struct_mutex and so serialising with us.
3866 for_each_intel_crtc(dev, crtc) {
3867 if (atomic_read(&crtc->unpin_work_count) == 0)
3870 if (crtc->unpin_work)
3871 intel_wait_for_vblank(dev, crtc->pipe);
3879 static void page_flip_completed(struct intel_crtc *intel_crtc)
3881 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
3882 struct intel_unpin_work *work = intel_crtc->unpin_work;
3884 /* ensure that the unpin work is consistent wrt ->pending. */
3886 intel_crtc->unpin_work = NULL;
3889 drm_send_vblank_event(intel_crtc->base.dev,
3893 drm_crtc_vblank_put(&intel_crtc->base);
3895 wake_up_all(&dev_priv->pending_flip_queue);
3896 queue_work(dev_priv->wq, &work->work);
3898 trace_i915_flip_complete(intel_crtc->plane,
3899 work->pending_flip_obj);
3902 void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
3904 struct drm_device *dev = crtc->dev;
3905 struct drm_i915_private *dev_priv = dev->dev_private;
3907 WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
3908 if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue,
3909 !intel_crtc_has_pending_flip(crtc),
3911 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3913 spin_lock_irq(&dev->event_lock);
3914 if (intel_crtc->unpin_work) {
3915 WARN_ONCE(1, "Removing stuck page flip\n");
3916 page_flip_completed(intel_crtc);
3918 spin_unlock_irq(&dev->event_lock);
3921 if (crtc->primary->fb) {
3922 mutex_lock(&dev->struct_mutex);
3923 intel_finish_fb(crtc->primary->fb);
3924 mutex_unlock(&dev->struct_mutex);
3928 /* Program iCLKIP clock to the desired frequency */
3929 static void lpt_program_iclkip(struct drm_crtc *crtc)
3931 struct drm_device *dev = crtc->dev;
3932 struct drm_i915_private *dev_priv = dev->dev_private;
3933 int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock;
3934 u32 divsel, phaseinc, auxdiv, phasedir = 0;
3937 mutex_lock(&dev_priv->sb_lock);
3939 /* It is necessary to ungate the pixclk gate prior to programming
3940 * the divisors, and gate it back when it is done.
3942 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
3944 /* Disable SSCCTL */
3945 intel_sbi_write(dev_priv, SBI_SSCCTL6,
3946 intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
3950 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
3951 if (clock == 20000) {
3956 /* The iCLK virtual clock root frequency is in MHz,
3957 * but the adjusted_mode->crtc_clock in in KHz. To get the
3958 * divisors, it is necessary to divide one by another, so we
3959 * convert the virtual clock precision to KHz here for higher
3962 u32 iclk_virtual_root_freq = 172800 * 1000;
3963 u32 iclk_pi_range = 64;
3964 u32 desired_divisor, msb_divisor_value, pi_value;
3966 desired_divisor = (iclk_virtual_root_freq / clock);
3967 msb_divisor_value = desired_divisor / iclk_pi_range;
3968 pi_value = desired_divisor % iclk_pi_range;
3971 divsel = msb_divisor_value - 2;
3972 phaseinc = pi_value;
3975 /* This should not happen with any sane values */
3976 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
3977 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
3978 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
3979 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
3981 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
3988 /* Program SSCDIVINTPHASE6 */
3989 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
3990 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
3991 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
3992 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
3993 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
3994 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
3995 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
3996 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
3998 /* Program SSCAUXDIV */
3999 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4000 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4001 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
4002 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
4004 /* Enable modulator and associated divider */
4005 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4006 temp &= ~SBI_SSCCTL_DISABLE;
4007 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4009 /* Wait for initialization time */
4012 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
4014 mutex_unlock(&dev_priv->sb_lock);
4017 static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
4018 enum pipe pch_transcoder)
4020 struct drm_device *dev = crtc->base.dev;
4021 struct drm_i915_private *dev_priv = dev->dev_private;
4022 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
4024 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
4025 I915_READ(HTOTAL(cpu_transcoder)));
4026 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
4027 I915_READ(HBLANK(cpu_transcoder)));
4028 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
4029 I915_READ(HSYNC(cpu_transcoder)));
4031 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
4032 I915_READ(VTOTAL(cpu_transcoder)));
4033 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
4034 I915_READ(VBLANK(cpu_transcoder)));
4035 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
4036 I915_READ(VSYNC(cpu_transcoder)));
4037 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
4038 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4041 static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable)
4043 struct drm_i915_private *dev_priv = dev->dev_private;
4046 temp = I915_READ(SOUTH_CHICKEN1);
4047 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
4050 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4051 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4053 temp &= ~FDI_BC_BIFURCATION_SELECT;
4055 temp |= FDI_BC_BIFURCATION_SELECT;
4057 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
4058 I915_WRITE(SOUTH_CHICKEN1, temp);
4059 POSTING_READ(SOUTH_CHICKEN1);
4062 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
4064 struct drm_device *dev = intel_crtc->base.dev;
4066 switch (intel_crtc->pipe) {
4070 if (intel_crtc->config->fdi_lanes > 2)
4071 cpt_set_fdi_bc_bifurcation(dev, false);
4073 cpt_set_fdi_bc_bifurcation(dev, true);
4077 cpt_set_fdi_bc_bifurcation(dev, true);
4086 * Enable PCH resources required for PCH ports:
4088 * - FDI training & RX/TX
4089 * - update transcoder timings
4090 * - DP transcoding bits
4093 static void ironlake_pch_enable(struct drm_crtc *crtc)
4095 struct drm_device *dev = crtc->dev;
4096 struct drm_i915_private *dev_priv = dev->dev_private;
4097 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4098 int pipe = intel_crtc->pipe;
4101 assert_pch_transcoder_disabled(dev_priv, pipe);
4103 if (IS_IVYBRIDGE(dev))
4104 ivybridge_update_fdi_bc_bifurcation(intel_crtc);
4106 /* Write the TU size bits before fdi link training, so that error
4107 * detection works. */
4108 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4109 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4111 /* For PCH output, training FDI link */
4112 dev_priv->display.fdi_link_train(crtc);
4114 /* We need to program the right clock selection before writing the pixel
4115 * mutliplier into the DPLL. */
4116 if (HAS_PCH_CPT(dev)) {
4119 temp = I915_READ(PCH_DPLL_SEL);
4120 temp |= TRANS_DPLL_ENABLE(pipe);
4121 sel = TRANS_DPLLB_SEL(pipe);
4122 if (intel_crtc->config->shared_dpll == DPLL_ID_PCH_PLL_B)
4126 I915_WRITE(PCH_DPLL_SEL, temp);
4129 /* XXX: pch pll's can be enabled any time before we enable the PCH
4130 * transcoder, and we actually should do this to not upset any PCH
4131 * transcoder that already use the clock when we share it.
4133 * Note that enable_shared_dpll tries to do the right thing, but
4134 * get_shared_dpll unconditionally resets the pll - we need that to have
4135 * the right LVDS enable sequence. */
4136 intel_enable_shared_dpll(intel_crtc);
4138 /* set transcoder timing, panel must allow it */
4139 assert_panel_unlocked(dev_priv, pipe);
4140 ironlake_pch_transcoder_set_timings(intel_crtc, pipe);
4142 intel_fdi_normal_train(crtc);
4144 /* For PCH DP, enable TRANS_DP_CTL */
4145 if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) {
4146 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
4147 reg = TRANS_DP_CTL(pipe);
4148 temp = I915_READ(reg);
4149 temp &= ~(TRANS_DP_PORT_SEL_MASK |
4150 TRANS_DP_SYNC_MASK |
4152 temp |= TRANS_DP_OUTPUT_ENABLE;
4153 temp |= bpc << 9; /* same format but at 11:9 */
4155 if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
4156 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
4157 if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
4158 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
4160 switch (intel_trans_dp_port_sel(crtc)) {
4162 temp |= TRANS_DP_PORT_SEL_B;
4165 temp |= TRANS_DP_PORT_SEL_C;
4168 temp |= TRANS_DP_PORT_SEL_D;
4174 I915_WRITE(reg, temp);
4177 ironlake_enable_pch_transcoder(dev_priv, pipe);
4180 static void lpt_pch_enable(struct drm_crtc *crtc)
4182 struct drm_device *dev = crtc->dev;
4183 struct drm_i915_private *dev_priv = dev->dev_private;
4184 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4185 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
4187 assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A);
4189 lpt_program_iclkip(crtc);
4191 /* Set transcoder timing. */
4192 ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A);
4194 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
4197 struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc,
4198 struct intel_crtc_state *crtc_state)
4200 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
4201 struct intel_shared_dpll *pll;
4202 struct intel_shared_dpll_config *shared_dpll;
4203 enum intel_dpll_id i;
4205 shared_dpll = intel_atomic_get_shared_dpll_state(crtc_state->base.state);
4207 if (HAS_PCH_IBX(dev_priv->dev)) {
4208 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
4209 i = (enum intel_dpll_id) crtc->pipe;
4210 pll = &dev_priv->shared_dplls[i];
4212 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
4213 crtc->base.base.id, pll->name);
4215 WARN_ON(shared_dpll[i].crtc_mask);
4220 if (IS_BROXTON(dev_priv->dev)) {
4221 /* PLL is attached to port in bxt */
4222 struct intel_encoder *encoder;
4223 struct intel_digital_port *intel_dig_port;
4225 encoder = intel_ddi_get_crtc_new_encoder(crtc_state);
4226 if (WARN_ON(!encoder))
4229 intel_dig_port = enc_to_dig_port(&encoder->base);
4230 /* 1:1 mapping between ports and PLLs */
4231 i = (enum intel_dpll_id)intel_dig_port->port;
4232 pll = &dev_priv->shared_dplls[i];
4233 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
4234 crtc->base.base.id, pll->name);
4235 WARN_ON(shared_dpll[i].crtc_mask);
4240 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
4241 pll = &dev_priv->shared_dplls[i];
4243 /* Only want to check enabled timings first */
4244 if (shared_dpll[i].crtc_mask == 0)
4247 if (memcmp(&crtc_state->dpll_hw_state,
4248 &shared_dpll[i].hw_state,
4249 sizeof(crtc_state->dpll_hw_state)) == 0) {
4250 DRM_DEBUG_KMS("CRTC:%d sharing existing %s (crtc mask 0x%08x, ative %d)\n",
4251 crtc->base.base.id, pll->name,
4252 shared_dpll[i].crtc_mask,
4258 /* Ok no matching timings, maybe there's a free one? */
4259 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
4260 pll = &dev_priv->shared_dplls[i];
4261 if (shared_dpll[i].crtc_mask == 0) {
4262 DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
4263 crtc->base.base.id, pll->name);
4271 if (shared_dpll[i].crtc_mask == 0)
4272 shared_dpll[i].hw_state =
4273 crtc_state->dpll_hw_state;
4275 crtc_state->shared_dpll = i;
4276 DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name,
4277 pipe_name(crtc->pipe));
4279 shared_dpll[i].crtc_mask |= 1 << crtc->pipe;
4284 static void intel_shared_dpll_commit(struct drm_atomic_state *state)
4286 struct drm_i915_private *dev_priv = to_i915(state->dev);
4287 struct intel_shared_dpll_config *shared_dpll;
4288 struct intel_shared_dpll *pll;
4289 enum intel_dpll_id i;
4291 if (!to_intel_atomic_state(state)->dpll_set)
4294 shared_dpll = to_intel_atomic_state(state)->shared_dpll;
4295 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
4296 pll = &dev_priv->shared_dplls[i];
4297 pll->config = shared_dpll[i];
4301 static void cpt_verify_modeset(struct drm_device *dev, int pipe)
4303 struct drm_i915_private *dev_priv = dev->dev_private;
4304 int dslreg = PIPEDSL(pipe);
4307 temp = I915_READ(dslreg);
4309 if (wait_for(I915_READ(dslreg) != temp, 5)) {
4310 if (wait_for(I915_READ(dslreg) != temp, 5))
4311 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
4316 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
4317 unsigned scaler_user, int *scaler_id, unsigned int rotation,
4318 int src_w, int src_h, int dst_w, int dst_h)
4320 struct intel_crtc_scaler_state *scaler_state =
4321 &crtc_state->scaler_state;
4322 struct intel_crtc *intel_crtc =
4323 to_intel_crtc(crtc_state->base.crtc);
4326 need_scaling = intel_rotation_90_or_270(rotation) ?
4327 (src_h != dst_w || src_w != dst_h):
4328 (src_w != dst_w || src_h != dst_h);
4331 * if plane is being disabled or scaler is no more required or force detach
4332 * - free scaler binded to this plane/crtc
4333 * - in order to do this, update crtc->scaler_usage
4335 * Here scaler state in crtc_state is set free so that
4336 * scaler can be assigned to other user. Actual register
4337 * update to free the scaler is done in plane/panel-fit programming.
4338 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4340 if (force_detach || !need_scaling) {
4341 if (*scaler_id >= 0) {
4342 scaler_state->scaler_users &= ~(1 << scaler_user);
4343 scaler_state->scalers[*scaler_id].in_use = 0;
4345 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4346 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4347 intel_crtc->pipe, scaler_user, *scaler_id,
4348 scaler_state->scaler_users);
4355 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
4356 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
4358 src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
4359 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) {
4360 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4361 "size is out of scaler range\n",
4362 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
4366 /* mark this plane as a scaler user in crtc_state */
4367 scaler_state->scaler_users |= (1 << scaler_user);
4368 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4369 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4370 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
4371 scaler_state->scaler_users);
4377 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4379 * @state: crtc's scaler state
4382 * 0 - scaler_usage updated successfully
4383 * error - requested scaling cannot be supported or other error condition
4385 int skl_update_scaler_crtc(struct intel_crtc_state *state)
4387 struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc);
4388 struct drm_display_mode *adjusted_mode =
4389 &state->base.adjusted_mode;
4391 DRM_DEBUG_KMS("Updating scaler for [CRTC:%i] scaler_user index %u.%u\n",
4392 intel_crtc->base.base.id, intel_crtc->pipe, SKL_CRTC_INDEX);
4394 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
4395 &state->scaler_state.scaler_id, DRM_ROTATE_0,
4396 state->pipe_src_w, state->pipe_src_h,
4397 adjusted_mode->hdisplay, adjusted_mode->vdisplay);
4401 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4403 * @state: crtc's scaler state
4404 * @plane_state: atomic plane state to update
4407 * 0 - scaler_usage updated successfully
4408 * error - requested scaling cannot be supported or other error condition
4410 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
4411 struct intel_plane_state *plane_state)
4414 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
4415 struct intel_plane *intel_plane =
4416 to_intel_plane(plane_state->base.plane);
4417 struct drm_framebuffer *fb = plane_state->base.fb;
4420 bool force_detach = !fb || !plane_state->visible;
4422 DRM_DEBUG_KMS("Updating scaler for [PLANE:%d] scaler_user index %u.%u\n",
4423 intel_plane->base.base.id, intel_crtc->pipe,
4424 drm_plane_index(&intel_plane->base));
4426 ret = skl_update_scaler(crtc_state, force_detach,
4427 drm_plane_index(&intel_plane->base),
4428 &plane_state->scaler_id,
4429 plane_state->base.rotation,
4430 drm_rect_width(&plane_state->src) >> 16,
4431 drm_rect_height(&plane_state->src) >> 16,
4432 drm_rect_width(&plane_state->dst),
4433 drm_rect_height(&plane_state->dst));
4435 if (ret || plane_state->scaler_id < 0)
4438 /* check colorkey */
4439 if (plane_state->ckey.flags != I915_SET_COLORKEY_NONE) {
4440 DRM_DEBUG_KMS("[PLANE:%d] scaling with color key not allowed",
4441 intel_plane->base.base.id);
4445 /* Check src format */
4446 switch (fb->pixel_format) {
4447 case DRM_FORMAT_RGB565:
4448 case DRM_FORMAT_XBGR8888:
4449 case DRM_FORMAT_XRGB8888:
4450 case DRM_FORMAT_ABGR8888:
4451 case DRM_FORMAT_ARGB8888:
4452 case DRM_FORMAT_XRGB2101010:
4453 case DRM_FORMAT_XBGR2101010:
4454 case DRM_FORMAT_YUYV:
4455 case DRM_FORMAT_YVYU:
4456 case DRM_FORMAT_UYVY:
4457 case DRM_FORMAT_VYUY:
4460 DRM_DEBUG_KMS("[PLANE:%d] FB:%d unsupported scaling format 0x%x\n",
4461 intel_plane->base.base.id, fb->base.id, fb->pixel_format);
4468 static void skylake_scaler_disable(struct intel_crtc *crtc)
4472 for (i = 0; i < crtc->num_scalers; i++)
4473 skl_detach_scaler(crtc, i);
4476 static void skylake_pfit_enable(struct intel_crtc *crtc)
4478 struct drm_device *dev = crtc->base.dev;
4479 struct drm_i915_private *dev_priv = dev->dev_private;
4480 int pipe = crtc->pipe;
4481 struct intel_crtc_scaler_state *scaler_state =
4482 &crtc->config->scaler_state;
4484 DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config);
4486 if (crtc->config->pch_pfit.enabled) {
4489 if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) {
4490 DRM_ERROR("Requesting pfit without getting a scaler first\n");
4494 id = scaler_state->scaler_id;
4495 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
4496 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
4497 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos);
4498 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size);
4500 DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc->config, id);
4504 static void ironlake_pfit_enable(struct intel_crtc *crtc)
4506 struct drm_device *dev = crtc->base.dev;
4507 struct drm_i915_private *dev_priv = dev->dev_private;
4508 int pipe = crtc->pipe;
4510 if (crtc->config->pch_pfit.enabled) {
4511 /* Force use of hard-coded filter coefficients
4512 * as some pre-programmed values are broken,
4515 if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
4516 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
4517 PF_PIPE_SEL_IVB(pipe));
4519 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
4520 I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos);
4521 I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size);
4525 void hsw_enable_ips(struct intel_crtc *crtc)
4527 struct drm_device *dev = crtc->base.dev;
4528 struct drm_i915_private *dev_priv = dev->dev_private;
4530 if (!crtc->config->ips_enabled)
4533 /* We can only enable IPS after we enable a plane and wait for a vblank */
4534 intel_wait_for_vblank(dev, crtc->pipe);
4536 assert_plane_enabled(dev_priv, crtc->plane);
4537 if (IS_BROADWELL(dev)) {
4538 mutex_lock(&dev_priv->rps.hw_lock);
4539 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000));
4540 mutex_unlock(&dev_priv->rps.hw_lock);
4541 /* Quoting Art Runyan: "its not safe to expect any particular
4542 * value in IPS_CTL bit 31 after enabling IPS through the
4543 * mailbox." Moreover, the mailbox may return a bogus state,
4544 * so we need to just enable it and continue on.
4547 I915_WRITE(IPS_CTL, IPS_ENABLE);
4548 /* The bit only becomes 1 in the next vblank, so this wait here
4549 * is essentially intel_wait_for_vblank. If we don't have this
4550 * and don't wait for vblanks until the end of crtc_enable, then
4551 * the HW state readout code will complain that the expected
4552 * IPS_CTL value is not the one we read. */
4553 if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50))
4554 DRM_ERROR("Timed out waiting for IPS enable\n");
4558 void hsw_disable_ips(struct intel_crtc *crtc)
4560 struct drm_device *dev = crtc->base.dev;
4561 struct drm_i915_private *dev_priv = dev->dev_private;
4563 if (!crtc->config->ips_enabled)
4566 assert_plane_enabled(dev_priv, crtc->plane);
4567 if (IS_BROADWELL(dev)) {
4568 mutex_lock(&dev_priv->rps.hw_lock);
4569 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
4570 mutex_unlock(&dev_priv->rps.hw_lock);
4571 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4572 if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42))
4573 DRM_ERROR("Timed out waiting for IPS disable\n");
4575 I915_WRITE(IPS_CTL, 0);
4576 POSTING_READ(IPS_CTL);
4579 /* We need to wait for a vblank before we can disable the plane. */
4580 intel_wait_for_vblank(dev, crtc->pipe);
4583 /** Loads the palette/gamma unit for the CRTC with the prepared values */
4584 static void intel_crtc_load_lut(struct drm_crtc *crtc)
4586 struct drm_device *dev = crtc->dev;
4587 struct drm_i915_private *dev_priv = dev->dev_private;
4588 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4589 enum pipe pipe = intel_crtc->pipe;
4590 int palreg = PALETTE(pipe);
4592 bool reenable_ips = false;
4594 /* The clocks have to be on to load the palette. */
4595 if (!crtc->state->active)
4598 if (HAS_GMCH_DISPLAY(dev_priv->dev)) {
4599 if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI))
4600 assert_dsi_pll_enabled(dev_priv);
4602 assert_pll_enabled(dev_priv, pipe);
4605 /* use legacy palette for Ironlake */
4606 if (!HAS_GMCH_DISPLAY(dev))
4607 palreg = LGC_PALETTE(pipe);
4609 /* Workaround : Do not read or write the pipe palette/gamma data while
4610 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
4612 if (IS_HASWELL(dev) && intel_crtc->config->ips_enabled &&
4613 ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) ==
4614 GAMMA_MODE_MODE_SPLIT)) {
4615 hsw_disable_ips(intel_crtc);
4616 reenable_ips = true;
4619 for (i = 0; i < 256; i++) {
4620 I915_WRITE(palreg + 4 * i,
4621 (intel_crtc->lut_r[i] << 16) |
4622 (intel_crtc->lut_g[i] << 8) |
4623 intel_crtc->lut_b[i]);
4627 hsw_enable_ips(intel_crtc);
4630 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
4632 if (intel_crtc->overlay) {
4633 struct drm_device *dev = intel_crtc->base.dev;
4634 struct drm_i915_private *dev_priv = dev->dev_private;
4636 mutex_lock(&dev->struct_mutex);
4637 dev_priv->mm.interruptible = false;
4638 (void) intel_overlay_switch_off(intel_crtc->overlay);
4639 dev_priv->mm.interruptible = true;
4640 mutex_unlock(&dev->struct_mutex);
4643 /* Let userspace switch the overlay on again. In most cases userspace
4644 * has to recompute where to put it anyway.
4649 * intel_post_enable_primary - Perform operations after enabling primary plane
4650 * @crtc: the CRTC whose primary plane was just enabled
4652 * Performs potentially sleeping operations that must be done after the primary
4653 * plane is enabled, such as updating FBC and IPS. Note that this may be
4654 * called due to an explicit primary plane update, or due to an implicit
4655 * re-enable that is caused when a sprite plane is updated to no longer
4656 * completely hide the primary plane.
4659 intel_post_enable_primary(struct drm_crtc *crtc)
4661 struct drm_device *dev = crtc->dev;
4662 struct drm_i915_private *dev_priv = dev->dev_private;
4663 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4664 int pipe = intel_crtc->pipe;
4667 * BDW signals flip done immediately if the plane
4668 * is disabled, even if the plane enable is already
4669 * armed to occur at the next vblank :(
4671 if (IS_BROADWELL(dev))
4672 intel_wait_for_vblank(dev, pipe);
4675 * FIXME IPS should be fine as long as one plane is
4676 * enabled, but in practice it seems to have problems
4677 * when going from primary only to sprite only and vice
4680 hsw_enable_ips(intel_crtc);
4683 * Gen2 reports pipe underruns whenever all planes are disabled.
4684 * So don't enable underrun reporting before at least some planes
4686 * FIXME: Need to fix the logic to work when we turn off all planes
4687 * but leave the pipe running.
4690 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
4692 /* Underruns don't raise interrupts, so check manually. */
4693 if (HAS_GMCH_DISPLAY(dev))
4694 i9xx_check_fifo_underruns(dev_priv);
4698 * intel_pre_disable_primary - Perform operations before disabling primary plane
4699 * @crtc: the CRTC whose primary plane is to be disabled
4701 * Performs potentially sleeping operations that must be done before the
4702 * primary plane is disabled, such as updating FBC and IPS. Note that this may
4703 * be called due to an explicit primary plane update, or due to an implicit
4704 * disable that is caused when a sprite plane completely hides the primary
4708 intel_pre_disable_primary(struct drm_crtc *crtc)
4710 struct drm_device *dev = crtc->dev;
4711 struct drm_i915_private *dev_priv = dev->dev_private;
4712 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4713 int pipe = intel_crtc->pipe;
4716 * Gen2 reports pipe underruns whenever all planes are disabled.
4717 * So diasble underrun reporting before all the planes get disabled.
4718 * FIXME: Need to fix the logic to work when we turn off all planes
4719 * but leave the pipe running.
4722 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
4725 * Vblank time updates from the shadow to live plane control register
4726 * are blocked if the memory self-refresh mode is active at that
4727 * moment. So to make sure the plane gets truly disabled, disable
4728 * first the self-refresh mode. The self-refresh enable bit in turn
4729 * will be checked/applied by the HW only at the next frame start
4730 * event which is after the vblank start event, so we need to have a
4731 * wait-for-vblank between disabling the plane and the pipe.
4733 if (HAS_GMCH_DISPLAY(dev)) {
4734 intel_set_memory_cxsr(dev_priv, false);
4735 dev_priv->wm.vlv.cxsr = false;
4736 intel_wait_for_vblank(dev, pipe);
4740 * FIXME IPS should be fine as long as one plane is
4741 * enabled, but in practice it seems to have problems
4742 * when going from primary only to sprite only and vice
4745 hsw_disable_ips(intel_crtc);
4748 static void intel_post_plane_update(struct intel_crtc *crtc)
4750 struct intel_crtc_atomic_commit *atomic = &crtc->atomic;
4751 struct drm_device *dev = crtc->base.dev;
4752 struct drm_i915_private *dev_priv = dev->dev_private;
4753 struct drm_plane *plane;
4755 if (atomic->wait_vblank)
4756 intel_wait_for_vblank(dev, crtc->pipe);
4758 intel_frontbuffer_flip(dev, atomic->fb_bits);
4760 if (atomic->disable_cxsr)
4761 crtc->wm.cxsr_allowed = true;
4763 if (crtc->atomic.update_wm_post)
4764 intel_update_watermarks(&crtc->base);
4766 if (atomic->update_fbc)
4767 intel_fbc_update(dev_priv);
4769 if (atomic->post_enable_primary)
4770 intel_post_enable_primary(&crtc->base);
4772 drm_for_each_plane_mask(plane, dev, atomic->update_sprite_watermarks)
4773 intel_update_sprite_watermarks(plane, &crtc->base,
4774 0, 0, 0, false, false);
4776 memset(atomic, 0, sizeof(*atomic));
4779 static void intel_pre_plane_update(struct intel_crtc *crtc)
4781 struct drm_device *dev = crtc->base.dev;
4782 struct drm_i915_private *dev_priv = dev->dev_private;
4783 struct intel_crtc_atomic_commit *atomic = &crtc->atomic;
4784 struct drm_plane *p;
4786 /* Track fb's for any planes being disabled */
4787 drm_for_each_plane_mask(p, dev, atomic->disabled_planes) {
4788 struct intel_plane *plane = to_intel_plane(p);
4790 mutex_lock(&dev->struct_mutex);
4791 i915_gem_track_fb(intel_fb_obj(plane->base.fb), NULL,
4792 plane->frontbuffer_bit);
4793 mutex_unlock(&dev->struct_mutex);
4796 if (atomic->wait_for_flips)
4797 intel_crtc_wait_for_pending_flips(&crtc->base);
4799 if (atomic->disable_fbc)
4800 intel_fbc_disable_crtc(crtc);
4802 if (crtc->atomic.disable_ips)
4803 hsw_disable_ips(crtc);
4805 if (atomic->pre_disable_primary)
4806 intel_pre_disable_primary(&crtc->base);
4808 if (atomic->disable_cxsr) {
4809 crtc->wm.cxsr_allowed = false;
4810 intel_set_memory_cxsr(dev_priv, false);
4814 static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask)
4816 struct drm_device *dev = crtc->dev;
4817 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4818 struct drm_plane *p;
4819 int pipe = intel_crtc->pipe;
4821 intel_crtc_dpms_overlay_disable(intel_crtc);
4823 drm_for_each_plane_mask(p, dev, plane_mask)
4824 to_intel_plane(p)->disable_plane(p, crtc);
4827 * FIXME: Once we grow proper nuclear flip support out of this we need
4828 * to compute the mask of flip planes precisely. For the time being
4829 * consider this a flip to a NULL plane.
4831 intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
4834 static void ironlake_crtc_enable(struct drm_crtc *crtc)
4836 struct drm_device *dev = crtc->dev;
4837 struct drm_i915_private *dev_priv = dev->dev_private;
4838 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4839 struct intel_encoder *encoder;
4840 int pipe = intel_crtc->pipe;
4842 if (WARN_ON(intel_crtc->active))
4845 if (intel_crtc->config->has_pch_encoder)
4846 intel_prepare_shared_dpll(intel_crtc);
4848 if (intel_crtc->config->has_dp_encoder)
4849 intel_dp_set_m_n(intel_crtc, M1_N1);
4851 intel_set_pipe_timings(intel_crtc);
4853 if (intel_crtc->config->has_pch_encoder) {
4854 intel_cpu_transcoder_set_m_n(intel_crtc,
4855 &intel_crtc->config->fdi_m_n, NULL);
4858 ironlake_set_pipeconf(crtc);
4860 intel_crtc->active = true;
4862 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
4863 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
4865 for_each_encoder_on_crtc(dev, crtc, encoder)
4866 if (encoder->pre_enable)
4867 encoder->pre_enable(encoder);
4869 if (intel_crtc->config->has_pch_encoder) {
4870 /* Note: FDI PLL enabling _must_ be done before we enable the
4871 * cpu pipes, hence this is separate from all the other fdi/pch
4873 ironlake_fdi_pll_enable(intel_crtc);
4875 assert_fdi_tx_disabled(dev_priv, pipe);
4876 assert_fdi_rx_disabled(dev_priv, pipe);
4879 ironlake_pfit_enable(intel_crtc);
4882 * On ILK+ LUT must be loaded before the pipe is running but with
4885 intel_crtc_load_lut(crtc);
4887 intel_update_watermarks(crtc);
4888 intel_enable_pipe(intel_crtc);
4890 if (intel_crtc->config->has_pch_encoder)
4891 ironlake_pch_enable(crtc);
4893 assert_vblank_disabled(crtc);
4894 drm_crtc_vblank_on(crtc);
4896 for_each_encoder_on_crtc(dev, crtc, encoder)
4897 encoder->enable(encoder);
4899 if (HAS_PCH_CPT(dev))
4900 cpt_verify_modeset(dev, intel_crtc->pipe);
4903 /* IPS only exists on ULT machines and is tied to pipe A. */
4904 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
4906 return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A;
4909 static void haswell_crtc_enable(struct drm_crtc *crtc)
4911 struct drm_device *dev = crtc->dev;
4912 struct drm_i915_private *dev_priv = dev->dev_private;
4913 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4914 struct intel_encoder *encoder;
4915 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
4916 struct intel_crtc_state *pipe_config =
4917 to_intel_crtc_state(crtc->state);
4919 if (WARN_ON(intel_crtc->active))
4922 if (intel_crtc_to_shared_dpll(intel_crtc))
4923 intel_enable_shared_dpll(intel_crtc);
4925 if (intel_crtc->config->has_dp_encoder)
4926 intel_dp_set_m_n(intel_crtc, M1_N1);
4928 intel_set_pipe_timings(intel_crtc);
4930 if (intel_crtc->config->cpu_transcoder != TRANSCODER_EDP) {
4931 I915_WRITE(PIPE_MULT(intel_crtc->config->cpu_transcoder),
4932 intel_crtc->config->pixel_multiplier - 1);
4935 if (intel_crtc->config->has_pch_encoder) {
4936 intel_cpu_transcoder_set_m_n(intel_crtc,
4937 &intel_crtc->config->fdi_m_n, NULL);
4940 haswell_set_pipeconf(crtc);
4942 intel_set_pipe_csc(crtc);
4944 intel_crtc->active = true;
4946 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
4947 for_each_encoder_on_crtc(dev, crtc, encoder)
4948 if (encoder->pre_enable)
4949 encoder->pre_enable(encoder);
4951 if (intel_crtc->config->has_pch_encoder) {
4952 intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A,
4954 dev_priv->display.fdi_link_train(crtc);
4957 intel_ddi_enable_pipe_clock(intel_crtc);
4959 if (INTEL_INFO(dev)->gen == 9)
4960 skylake_pfit_enable(intel_crtc);
4961 else if (INTEL_INFO(dev)->gen < 9)
4962 ironlake_pfit_enable(intel_crtc);
4964 MISSING_CASE(INTEL_INFO(dev)->gen);
4967 * On ILK+ LUT must be loaded before the pipe is running but with
4970 intel_crtc_load_lut(crtc);
4972 intel_ddi_set_pipe_settings(crtc);
4973 intel_ddi_enable_transcoder_func(crtc);
4975 intel_update_watermarks(crtc);
4976 intel_enable_pipe(intel_crtc);
4978 if (intel_crtc->config->has_pch_encoder)
4979 lpt_pch_enable(crtc);
4981 if (intel_crtc->config->dp_encoder_is_mst)
4982 intel_ddi_set_vc_payload_alloc(crtc, true);
4984 assert_vblank_disabled(crtc);
4985 drm_crtc_vblank_on(crtc);
4987 for_each_encoder_on_crtc(dev, crtc, encoder) {
4988 encoder->enable(encoder);
4989 intel_opregion_notify_encoder(encoder, true);
4992 /* If we change the relative order between pipe/planes enabling, we need
4993 * to change the workaround. */
4994 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
4995 if (IS_HASWELL(dev) && hsw_workaround_pipe != INVALID_PIPE) {
4996 intel_wait_for_vblank(dev, hsw_workaround_pipe);
4997 intel_wait_for_vblank(dev, hsw_workaround_pipe);
5001 static void ironlake_pfit_disable(struct intel_crtc *crtc)
5003 struct drm_device *dev = crtc->base.dev;
5004 struct drm_i915_private *dev_priv = dev->dev_private;
5005 int pipe = crtc->pipe;
5007 /* To avoid upsetting the power well on haswell only disable the pfit if
5008 * it's in use. The hw state code will make sure we get this right. */
5009 if (crtc->config->pch_pfit.enabled) {
5010 I915_WRITE(PF_CTL(pipe), 0);
5011 I915_WRITE(PF_WIN_POS(pipe), 0);
5012 I915_WRITE(PF_WIN_SZ(pipe), 0);
5016 static void ironlake_crtc_disable(struct drm_crtc *crtc)
5018 struct drm_device *dev = crtc->dev;
5019 struct drm_i915_private *dev_priv = dev->dev_private;
5020 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5021 struct intel_encoder *encoder;
5022 int pipe = intel_crtc->pipe;
5025 for_each_encoder_on_crtc(dev, crtc, encoder)
5026 encoder->disable(encoder);
5028 drm_crtc_vblank_off(crtc);
5029 assert_vblank_disabled(crtc);
5031 if (intel_crtc->config->has_pch_encoder)
5032 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5034 intel_disable_pipe(intel_crtc);
5036 ironlake_pfit_disable(intel_crtc);
5038 if (intel_crtc->config->has_pch_encoder)
5039 ironlake_fdi_disable(crtc);
5041 for_each_encoder_on_crtc(dev, crtc, encoder)
5042 if (encoder->post_disable)
5043 encoder->post_disable(encoder);
5045 if (intel_crtc->config->has_pch_encoder) {
5046 ironlake_disable_pch_transcoder(dev_priv, pipe);
5048 if (HAS_PCH_CPT(dev)) {
5049 /* disable TRANS_DP_CTL */
5050 reg = TRANS_DP_CTL(pipe);
5051 temp = I915_READ(reg);
5052 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
5053 TRANS_DP_PORT_SEL_MASK);
5054 temp |= TRANS_DP_PORT_SEL_NONE;
5055 I915_WRITE(reg, temp);
5057 /* disable DPLL_SEL */
5058 temp = I915_READ(PCH_DPLL_SEL);
5059 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
5060 I915_WRITE(PCH_DPLL_SEL, temp);
5063 ironlake_fdi_pll_disable(intel_crtc);
5066 intel_crtc->active = false;
5067 intel_update_watermarks(crtc);
5070 static void haswell_crtc_disable(struct drm_crtc *crtc)
5072 struct drm_device *dev = crtc->dev;
5073 struct drm_i915_private *dev_priv = dev->dev_private;
5074 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5075 struct intel_encoder *encoder;
5076 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
5078 for_each_encoder_on_crtc(dev, crtc, encoder) {
5079 intel_opregion_notify_encoder(encoder, false);
5080 encoder->disable(encoder);
5083 drm_crtc_vblank_off(crtc);
5084 assert_vblank_disabled(crtc);
5086 if (intel_crtc->config->has_pch_encoder)
5087 intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A,
5089 intel_disable_pipe(intel_crtc);
5091 if (intel_crtc->config->dp_encoder_is_mst)
5092 intel_ddi_set_vc_payload_alloc(crtc, false);
5094 intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
5096 if (INTEL_INFO(dev)->gen == 9)
5097 skylake_scaler_disable(intel_crtc);
5098 else if (INTEL_INFO(dev)->gen < 9)
5099 ironlake_pfit_disable(intel_crtc);
5101 MISSING_CASE(INTEL_INFO(dev)->gen);
5103 intel_ddi_disable_pipe_clock(intel_crtc);
5105 if (intel_crtc->config->has_pch_encoder) {
5106 lpt_disable_pch_transcoder(dev_priv);
5107 intel_ddi_fdi_disable(crtc);
5110 for_each_encoder_on_crtc(dev, crtc, encoder)
5111 if (encoder->post_disable)
5112 encoder->post_disable(encoder);
5114 intel_crtc->active = false;
5115 intel_update_watermarks(crtc);
5118 static void i9xx_pfit_enable(struct intel_crtc *crtc)
5120 struct drm_device *dev = crtc->base.dev;
5121 struct drm_i915_private *dev_priv = dev->dev_private;
5122 struct intel_crtc_state *pipe_config = crtc->config;
5124 if (!pipe_config->gmch_pfit.control)
5128 * The panel fitter should only be adjusted whilst the pipe is disabled,
5129 * according to register description and PRM.
5131 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
5132 assert_pipe_disabled(dev_priv, crtc->pipe);
5134 I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
5135 I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
5137 /* Border color in case we don't scale up to the full screen. Black by
5138 * default, change to something else for debugging. */
5139 I915_WRITE(BCLRPAT(crtc->pipe), 0);
5142 static enum intel_display_power_domain port_to_power_domain(enum port port)
5146 return POWER_DOMAIN_PORT_DDI_A_4_LANES;
5148 return POWER_DOMAIN_PORT_DDI_B_4_LANES;
5150 return POWER_DOMAIN_PORT_DDI_C_4_LANES;
5152 return POWER_DOMAIN_PORT_DDI_D_4_LANES;
5155 return POWER_DOMAIN_PORT_OTHER;
5159 #define for_each_power_domain(domain, mask) \
5160 for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
5161 if ((1 << (domain)) & (mask))
5163 enum intel_display_power_domain
5164 intel_display_port_power_domain(struct intel_encoder *intel_encoder)
5166 struct drm_device *dev = intel_encoder->base.dev;
5167 struct intel_digital_port *intel_dig_port;
5169 switch (intel_encoder->type) {
5170 case INTEL_OUTPUT_UNKNOWN:
5171 /* Only DDI platforms should ever use this output type */
5172 WARN_ON_ONCE(!HAS_DDI(dev));
5173 case INTEL_OUTPUT_DISPLAYPORT:
5174 case INTEL_OUTPUT_HDMI:
5175 case INTEL_OUTPUT_EDP:
5176 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
5177 return port_to_power_domain(intel_dig_port->port);
5178 case INTEL_OUTPUT_DP_MST:
5179 intel_dig_port = enc_to_mst(&intel_encoder->base)->primary;
5180 return port_to_power_domain(intel_dig_port->port);
5181 case INTEL_OUTPUT_ANALOG:
5182 return POWER_DOMAIN_PORT_CRT;
5183 case INTEL_OUTPUT_DSI:
5184 return POWER_DOMAIN_PORT_DSI;
5186 return POWER_DOMAIN_PORT_OTHER;
5190 static unsigned long get_crtc_power_domains(struct drm_crtc *crtc)
5192 struct drm_device *dev = crtc->dev;
5193 struct intel_encoder *intel_encoder;
5194 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5195 enum pipe pipe = intel_crtc->pipe;
5197 enum transcoder transcoder;
5199 if (!crtc->state->active)
5202 transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe);
5204 mask = BIT(POWER_DOMAIN_PIPE(pipe));
5205 mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder));
5206 if (intel_crtc->config->pch_pfit.enabled ||
5207 intel_crtc->config->pch_pfit.force_thru)
5208 mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
5210 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
5211 mask |= BIT(intel_display_port_power_domain(intel_encoder));
5216 static unsigned long modeset_get_crtc_power_domains(struct drm_crtc *crtc)
5218 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
5219 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5220 enum intel_display_power_domain domain;
5221 unsigned long domains, new_domains, old_domains;
5223 old_domains = intel_crtc->enabled_power_domains;
5224 intel_crtc->enabled_power_domains = new_domains = get_crtc_power_domains(crtc);
5226 domains = new_domains & ~old_domains;
5228 for_each_power_domain(domain, domains)
5229 intel_display_power_get(dev_priv, domain);
5231 return old_domains & ~new_domains;
5234 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
5235 unsigned long domains)
5237 enum intel_display_power_domain domain;
5239 for_each_power_domain(domain, domains)
5240 intel_display_power_put(dev_priv, domain);
5243 static void modeset_update_crtc_power_domains(struct drm_atomic_state *state)
5245 struct drm_device *dev = state->dev;
5246 struct drm_i915_private *dev_priv = dev->dev_private;
5247 unsigned long put_domains[I915_MAX_PIPES] = {};
5248 struct drm_crtc_state *crtc_state;
5249 struct drm_crtc *crtc;
5252 for_each_crtc_in_state(state, crtc, crtc_state, i) {
5253 if (needs_modeset(crtc->state))
5254 put_domains[to_intel_crtc(crtc)->pipe] =
5255 modeset_get_crtc_power_domains(crtc);
5258 if (dev_priv->display.modeset_commit_cdclk) {
5259 unsigned int cdclk = to_intel_atomic_state(state)->cdclk;
5261 if (cdclk != dev_priv->cdclk_freq &&
5262 !WARN_ON(!state->allow_modeset))
5263 dev_priv->display.modeset_commit_cdclk(state);
5266 for (i = 0; i < I915_MAX_PIPES; i++)
5268 modeset_put_power_domains(dev_priv, put_domains[i]);
5271 static void intel_update_max_cdclk(struct drm_device *dev)
5273 struct drm_i915_private *dev_priv = dev->dev_private;
5275 if (IS_SKYLAKE(dev)) {
5276 u32 limit = I915_READ(SKL_DFSM) & SKL_DFSM_CDCLK_LIMIT_MASK;
5278 if (limit == SKL_DFSM_CDCLK_LIMIT_675)
5279 dev_priv->max_cdclk_freq = 675000;
5280 else if (limit == SKL_DFSM_CDCLK_LIMIT_540)
5281 dev_priv->max_cdclk_freq = 540000;
5282 else if (limit == SKL_DFSM_CDCLK_LIMIT_450)
5283 dev_priv->max_cdclk_freq = 450000;
5285 dev_priv->max_cdclk_freq = 337500;
5286 } else if (IS_BROADWELL(dev)) {
5288 * FIXME with extra cooling we can allow
5289 * 540 MHz for ULX and 675 Mhz for ULT.
5290 * How can we know if extra cooling is
5291 * available? PCI ID, VTB, something else?
5293 if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT)
5294 dev_priv->max_cdclk_freq = 450000;
5295 else if (IS_BDW_ULX(dev))
5296 dev_priv->max_cdclk_freq = 450000;
5297 else if (IS_BDW_ULT(dev))
5298 dev_priv->max_cdclk_freq = 540000;
5300 dev_priv->max_cdclk_freq = 675000;
5301 } else if (IS_CHERRYVIEW(dev)) {
5302 dev_priv->max_cdclk_freq = 320000;
5303 } else if (IS_VALLEYVIEW(dev)) {
5304 dev_priv->max_cdclk_freq = 400000;
5306 /* otherwise assume cdclk is fixed */
5307 dev_priv->max_cdclk_freq = dev_priv->cdclk_freq;
5310 DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n",
5311 dev_priv->max_cdclk_freq);
5314 static void intel_update_cdclk(struct drm_device *dev)
5316 struct drm_i915_private *dev_priv = dev->dev_private;
5318 dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev);
5319 DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n",
5320 dev_priv->cdclk_freq);
5323 * Program the gmbus_freq based on the cdclk frequency.
5324 * BSpec erroneously claims we should aim for 4MHz, but
5325 * in fact 1MHz is the correct frequency.
5327 if (IS_VALLEYVIEW(dev)) {
5329 * Program the gmbus_freq based on the cdclk frequency.
5330 * BSpec erroneously claims we should aim for 4MHz, but
5331 * in fact 1MHz is the correct frequency.
5333 I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000));
5336 if (dev_priv->max_cdclk_freq == 0)
5337 intel_update_max_cdclk(dev);
5340 static void broxton_set_cdclk(struct drm_device *dev, int frequency)
5342 struct drm_i915_private *dev_priv = dev->dev_private;
5345 uint32_t current_freq;
5348 /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */
5349 switch (frequency) {
5351 divider = BXT_CDCLK_CD2X_DIV_SEL_4;
5352 ratio = BXT_DE_PLL_RATIO(60);
5355 divider = BXT_CDCLK_CD2X_DIV_SEL_2;
5356 ratio = BXT_DE_PLL_RATIO(60);
5359 divider = BXT_CDCLK_CD2X_DIV_SEL_1_5;
5360 ratio = BXT_DE_PLL_RATIO(60);
5363 divider = BXT_CDCLK_CD2X_DIV_SEL_1;
5364 ratio = BXT_DE_PLL_RATIO(60);
5367 divider = BXT_CDCLK_CD2X_DIV_SEL_1;
5368 ratio = BXT_DE_PLL_RATIO(65);
5372 * Bypass frequency with DE PLL disabled. Init ratio, divider
5373 * to suppress GCC warning.
5379 DRM_ERROR("unsupported CDCLK freq %d", frequency);
5384 mutex_lock(&dev_priv->rps.hw_lock);
5385 /* Inform power controller of upcoming frequency change */
5386 ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ,
5388 mutex_unlock(&dev_priv->rps.hw_lock);
5391 DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n",
5396 current_freq = I915_READ(CDCLK_CTL) & CDCLK_FREQ_DECIMAL_MASK;
5397 /* convert from .1 fixpoint MHz with -1MHz offset to kHz */
5398 current_freq = current_freq * 500 + 1000;
5401 * DE PLL has to be disabled when
5402 * - setting to 19.2MHz (bypass, PLL isn't used)
5403 * - before setting to 624MHz (PLL needs toggling)
5404 * - before setting to any frequency from 624MHz (PLL needs toggling)
5406 if (frequency == 19200 || frequency == 624000 ||
5407 current_freq == 624000) {
5408 I915_WRITE(BXT_DE_PLL_ENABLE, ~BXT_DE_PLL_PLL_ENABLE);
5410 if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK),
5412 DRM_ERROR("timout waiting for DE PLL unlock\n");
5415 if (frequency != 19200) {
5418 val = I915_READ(BXT_DE_PLL_CTL);
5419 val &= ~BXT_DE_PLL_RATIO_MASK;
5421 I915_WRITE(BXT_DE_PLL_CTL, val);
5423 I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE);
5425 if (wait_for(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK, 1))
5426 DRM_ERROR("timeout waiting for DE PLL lock\n");
5428 val = I915_READ(CDCLK_CTL);
5429 val &= ~BXT_CDCLK_CD2X_DIV_SEL_MASK;
5432 * Disable SSA Precharge when CD clock frequency < 500 MHz,
5435 val &= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE;
5436 if (frequency >= 500000)
5437 val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE;
5439 val &= ~CDCLK_FREQ_DECIMAL_MASK;
5440 /* convert from kHz to .1 fixpoint MHz with -1MHz offset */
5441 val |= (frequency - 1000) / 500;
5442 I915_WRITE(CDCLK_CTL, val);
5445 mutex_lock(&dev_priv->rps.hw_lock);
5446 ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ,
5447 DIV_ROUND_UP(frequency, 25000));
5448 mutex_unlock(&dev_priv->rps.hw_lock);
5451 DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n",
5456 intel_update_cdclk(dev);
5459 void broxton_init_cdclk(struct drm_device *dev)
5461 struct drm_i915_private *dev_priv = dev->dev_private;
5465 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
5466 * or else the reset will hang because there is no PCH to respond.
5467 * Move the handshake programming to initialization sequence.
5468 * Previously was left up to BIOS.
5470 val = I915_READ(HSW_NDE_RSTWRN_OPT);
5471 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
5472 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
5474 /* Enable PG1 for cdclk */
5475 intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
5477 /* check if cd clock is enabled */
5478 if (I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE) {
5479 DRM_DEBUG_KMS("Display already initialized\n");
5485 * - The initial CDCLK needs to be read from VBT.
5486 * Need to make this change after VBT has changes for BXT.
5487 * - check if setting the max (or any) cdclk freq is really necessary
5488 * here, it belongs to modeset time
5490 broxton_set_cdclk(dev, 624000);
5492 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
5493 POSTING_READ(DBUF_CTL);
5497 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
5498 DRM_ERROR("DBuf power enable timeout!\n");
5501 void broxton_uninit_cdclk(struct drm_device *dev)
5503 struct drm_i915_private *dev_priv = dev->dev_private;
5505 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
5506 POSTING_READ(DBUF_CTL);
5510 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
5511 DRM_ERROR("DBuf power disable timeout!\n");
5513 /* Set minimum (bypass) frequency, in effect turning off the DE PLL */
5514 broxton_set_cdclk(dev, 19200);
5516 intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS);
5519 static const struct skl_cdclk_entry {
5522 } skl_cdclk_frequencies[] = {
5523 { .freq = 308570, .vco = 8640 },
5524 { .freq = 337500, .vco = 8100 },
5525 { .freq = 432000, .vco = 8640 },
5526 { .freq = 450000, .vco = 8100 },
5527 { .freq = 540000, .vco = 8100 },
5528 { .freq = 617140, .vco = 8640 },
5529 { .freq = 675000, .vco = 8100 },
5532 static unsigned int skl_cdclk_decimal(unsigned int freq)
5534 return (freq - 1000) / 500;
5537 static unsigned int skl_cdclk_get_vco(unsigned int freq)
5541 for (i = 0; i < ARRAY_SIZE(skl_cdclk_frequencies); i++) {
5542 const struct skl_cdclk_entry *e = &skl_cdclk_frequencies[i];
5544 if (e->freq == freq)
5552 skl_dpll0_enable(struct drm_i915_private *dev_priv, unsigned int required_vco)
5554 unsigned int min_freq;
5557 /* select the minimum CDCLK before enabling DPLL 0 */
5558 val = I915_READ(CDCLK_CTL);
5559 val &= ~CDCLK_FREQ_SEL_MASK | ~CDCLK_FREQ_DECIMAL_MASK;
5560 val |= CDCLK_FREQ_337_308;
5562 if (required_vco == 8640)
5567 val = CDCLK_FREQ_337_308 | skl_cdclk_decimal(min_freq);
5569 I915_WRITE(CDCLK_CTL, val);
5570 POSTING_READ(CDCLK_CTL);
5573 * We always enable DPLL0 with the lowest link rate possible, but still
5574 * taking into account the VCO required to operate the eDP panel at the
5575 * desired frequency. The usual DP link rates operate with a VCO of
5576 * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640.
5577 * The modeset code is responsible for the selection of the exact link
5578 * rate later on, with the constraint of choosing a frequency that
5579 * works with required_vco.
5581 val = I915_READ(DPLL_CTRL1);
5583 val &= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | DPLL_CTRL1_SSC(SKL_DPLL0) |
5584 DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0));
5585 val |= DPLL_CTRL1_OVERRIDE(SKL_DPLL0);
5586 if (required_vco == 8640)
5587 val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080,
5590 val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810,
5593 I915_WRITE(DPLL_CTRL1, val);
5594 POSTING_READ(DPLL_CTRL1);
5596 I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) | LCPLL_PLL_ENABLE);
5598 if (wait_for(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK, 5))
5599 DRM_ERROR("DPLL0 not locked\n");
5602 static bool skl_cdclk_pcu_ready(struct drm_i915_private *dev_priv)
5607 /* inform PCU we want to change CDCLK */
5608 val = SKL_CDCLK_PREPARE_FOR_CHANGE;
5609 mutex_lock(&dev_priv->rps.hw_lock);
5610 ret = sandybridge_pcode_read(dev_priv, SKL_PCODE_CDCLK_CONTROL, &val);
5611 mutex_unlock(&dev_priv->rps.hw_lock);
5613 return ret == 0 && (val & SKL_CDCLK_READY_FOR_CHANGE);
5616 static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv)
5620 for (i = 0; i < 15; i++) {
5621 if (skl_cdclk_pcu_ready(dev_priv))
5629 static void skl_set_cdclk(struct drm_i915_private *dev_priv, unsigned int freq)
5631 struct drm_device *dev = dev_priv->dev;
5632 u32 freq_select, pcu_ack;
5634 DRM_DEBUG_DRIVER("Changing CDCLK to %dKHz\n", freq);
5636 if (!skl_cdclk_wait_for_pcu_ready(dev_priv)) {
5637 DRM_ERROR("failed to inform PCU about cdclk change\n");
5645 freq_select = CDCLK_FREQ_450_432;
5649 freq_select = CDCLK_FREQ_540;
5655 freq_select = CDCLK_FREQ_337_308;
5660 freq_select = CDCLK_FREQ_675_617;
5665 I915_WRITE(CDCLK_CTL, freq_select | skl_cdclk_decimal(freq));
5666 POSTING_READ(CDCLK_CTL);
5668 /* inform PCU of the change */
5669 mutex_lock(&dev_priv->rps.hw_lock);
5670 sandybridge_pcode_write(dev_priv, SKL_PCODE_CDCLK_CONTROL, pcu_ack);
5671 mutex_unlock(&dev_priv->rps.hw_lock);
5673 intel_update_cdclk(dev);
5676 void skl_uninit_cdclk(struct drm_i915_private *dev_priv)
5678 /* disable DBUF power */
5679 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
5680 POSTING_READ(DBUF_CTL);
5684 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
5685 DRM_ERROR("DBuf power disable timeout\n");
5688 I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & ~LCPLL_PLL_ENABLE);
5689 if (wait_for(!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK), 1))
5690 DRM_ERROR("Couldn't disable DPLL0\n");
5692 intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS);
5695 void skl_init_cdclk(struct drm_i915_private *dev_priv)
5698 unsigned int required_vco;
5700 /* enable PCH reset handshake */
5701 val = I915_READ(HSW_NDE_RSTWRN_OPT);
5702 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
5704 /* enable PG1 and Misc I/O */
5705 intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
5707 /* DPLL0 already enabed !? */
5708 if (I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE) {
5709 DRM_DEBUG_DRIVER("DPLL0 already running\n");
5714 required_vco = skl_cdclk_get_vco(dev_priv->skl_boot_cdclk);
5715 skl_dpll0_enable(dev_priv, required_vco);
5717 /* set CDCLK to the frequency the BIOS chose */
5718 skl_set_cdclk(dev_priv, dev_priv->skl_boot_cdclk);
5720 /* enable DBUF power */
5721 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
5722 POSTING_READ(DBUF_CTL);
5726 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
5727 DRM_ERROR("DBuf power enable timeout\n");
5730 /* returns HPLL frequency in kHz */
5731 static int valleyview_get_vco(struct drm_i915_private *dev_priv)
5733 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
5735 /* Obtain SKU information */
5736 mutex_lock(&dev_priv->sb_lock);
5737 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
5738 CCK_FUSE_HPLL_FREQ_MASK;
5739 mutex_unlock(&dev_priv->sb_lock);
5741 return vco_freq[hpll_freq] * 1000;
5744 /* Adjust CDclk dividers to allow high res or save power if possible */
5745 static void valleyview_set_cdclk(struct drm_device *dev, int cdclk)
5747 struct drm_i915_private *dev_priv = dev->dev_private;
5750 WARN_ON(dev_priv->display.get_display_clock_speed(dev)
5751 != dev_priv->cdclk_freq);
5753 if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */
5755 else if (cdclk == 266667)
5760 mutex_lock(&dev_priv->rps.hw_lock);
5761 val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
5762 val &= ~DSPFREQGUAR_MASK;
5763 val |= (cmd << DSPFREQGUAR_SHIFT);
5764 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
5765 if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
5766 DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT),
5768 DRM_ERROR("timed out waiting for CDclk change\n");
5770 mutex_unlock(&dev_priv->rps.hw_lock);
5772 mutex_lock(&dev_priv->sb_lock);
5774 if (cdclk == 400000) {
5777 divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1;
5779 /* adjust cdclk divider */
5780 val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
5781 val &= ~DISPLAY_FREQUENCY_VALUES;
5783 vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val);
5785 if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) &
5786 DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
5788 DRM_ERROR("timed out waiting for CDclk change\n");
5791 /* adjust self-refresh exit latency value */
5792 val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC);
5796 * For high bandwidth configs, we set a higher latency in the bunit
5797 * so that the core display fetch happens in time to avoid underruns.
5799 if (cdclk == 400000)
5800 val |= 4500 / 250; /* 4.5 usec */
5802 val |= 3000 / 250; /* 3.0 usec */
5803 vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val);
5805 mutex_unlock(&dev_priv->sb_lock);
5807 intel_update_cdclk(dev);
5810 static void cherryview_set_cdclk(struct drm_device *dev, int cdclk)
5812 struct drm_i915_private *dev_priv = dev->dev_private;
5815 WARN_ON(dev_priv->display.get_display_clock_speed(dev)
5816 != dev_priv->cdclk_freq);
5825 MISSING_CASE(cdclk);
5830 * Specs are full of misinformation, but testing on actual
5831 * hardware has shown that we just need to write the desired
5832 * CCK divider into the Punit register.
5834 cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1;
5836 mutex_lock(&dev_priv->rps.hw_lock);
5837 val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
5838 val &= ~DSPFREQGUAR_MASK_CHV;
5839 val |= (cmd << DSPFREQGUAR_SHIFT_CHV);
5840 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
5841 if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
5842 DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV),
5844 DRM_ERROR("timed out waiting for CDclk change\n");
5846 mutex_unlock(&dev_priv->rps.hw_lock);
5848 intel_update_cdclk(dev);
5851 static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv,
5854 int freq_320 = (dev_priv->hpll_freq << 1) % 320000 != 0 ? 333333 : 320000;
5855 int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90;
5858 * Really only a few cases to deal with, as only 4 CDclks are supported:
5861 * 320/333MHz (depends on HPLL freq)
5863 * So we check to see whether we're above 90% (VLV) or 95% (CHV)
5864 * of the lower bin and adjust if needed.
5866 * We seem to get an unstable or solid color picture at 200MHz.
5867 * Not sure what's wrong. For now use 200MHz only when all pipes
5870 if (!IS_CHERRYVIEW(dev_priv) &&
5871 max_pixclk > freq_320*limit/100)
5873 else if (max_pixclk > 266667*limit/100)
5875 else if (max_pixclk > 0)
5881 static int broxton_calc_cdclk(struct drm_i915_private *dev_priv,
5886 * - remove the guardband, it's not needed on BXT
5887 * - set 19.2MHz bypass frequency if there are no active pipes
5889 if (max_pixclk > 576000*9/10)
5891 else if (max_pixclk > 384000*9/10)
5893 else if (max_pixclk > 288000*9/10)
5895 else if (max_pixclk > 144000*9/10)
5901 /* Compute the max pixel clock for new configuration. Uses atomic state if
5902 * that's non-NULL, look at current state otherwise. */
5903 static int intel_mode_max_pixclk(struct drm_device *dev,
5904 struct drm_atomic_state *state)
5906 struct intel_crtc *intel_crtc;
5907 struct intel_crtc_state *crtc_state;
5910 for_each_intel_crtc(dev, intel_crtc) {
5911 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
5912 if (IS_ERR(crtc_state))
5913 return PTR_ERR(crtc_state);
5915 if (!crtc_state->base.enable)
5918 max_pixclk = max(max_pixclk,
5919 crtc_state->base.adjusted_mode.crtc_clock);
5925 static int valleyview_modeset_calc_cdclk(struct drm_atomic_state *state)
5927 struct drm_device *dev = state->dev;
5928 struct drm_i915_private *dev_priv = dev->dev_private;
5929 int max_pixclk = intel_mode_max_pixclk(dev, state);
5934 to_intel_atomic_state(state)->cdclk =
5935 valleyview_calc_cdclk(dev_priv, max_pixclk);
5940 static int broxton_modeset_calc_cdclk(struct drm_atomic_state *state)
5942 struct drm_device *dev = state->dev;
5943 struct drm_i915_private *dev_priv = dev->dev_private;
5944 int max_pixclk = intel_mode_max_pixclk(dev, state);
5949 to_intel_atomic_state(state)->cdclk =
5950 broxton_calc_cdclk(dev_priv, max_pixclk);
5955 static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv)
5957 unsigned int credits, default_credits;
5959 if (IS_CHERRYVIEW(dev_priv))
5960 default_credits = PFI_CREDIT(12);
5962 default_credits = PFI_CREDIT(8);
5964 if (DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 1000) >= dev_priv->rps.cz_freq) {
5965 /* CHV suggested value is 31 or 63 */
5966 if (IS_CHERRYVIEW(dev_priv))
5967 credits = PFI_CREDIT_63;
5969 credits = PFI_CREDIT(15);
5971 credits = default_credits;
5975 * WA - write default credits before re-programming
5976 * FIXME: should we also set the resend bit here?
5978 I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE |
5981 I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE |
5982 credits | PFI_CREDIT_RESEND);
5985 * FIXME is this guaranteed to clear
5986 * immediately or should we poll for it?
5988 WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND);
5991 static void valleyview_modeset_commit_cdclk(struct drm_atomic_state *old_state)
5993 struct drm_device *dev = old_state->dev;
5994 unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk;
5995 struct drm_i915_private *dev_priv = dev->dev_private;
5998 * FIXME: We can end up here with all power domains off, yet
5999 * with a CDCLK frequency other than the minimum. To account
6000 * for this take the PIPE-A power domain, which covers the HW
6001 * blocks needed for the following programming. This can be
6002 * removed once it's guaranteed that we get here either with
6003 * the minimum CDCLK set, or the required power domains
6006 intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A);
6008 if (IS_CHERRYVIEW(dev))
6009 cherryview_set_cdclk(dev, req_cdclk);
6011 valleyview_set_cdclk(dev, req_cdclk);
6013 vlv_program_pfi_credits(dev_priv);
6015 intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A);
6018 static void valleyview_crtc_enable(struct drm_crtc *crtc)
6020 struct drm_device *dev = crtc->dev;
6021 struct drm_i915_private *dev_priv = to_i915(dev);
6022 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6023 struct intel_encoder *encoder;
6024 int pipe = intel_crtc->pipe;
6027 if (WARN_ON(intel_crtc->active))
6030 is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI);
6033 if (IS_CHERRYVIEW(dev))
6034 chv_prepare_pll(intel_crtc, intel_crtc->config);
6036 vlv_prepare_pll(intel_crtc, intel_crtc->config);
6039 if (intel_crtc->config->has_dp_encoder)
6040 intel_dp_set_m_n(intel_crtc, M1_N1);
6042 intel_set_pipe_timings(intel_crtc);
6044 if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) {
6045 struct drm_i915_private *dev_priv = dev->dev_private;
6047 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6048 I915_WRITE(CHV_CANVAS(pipe), 0);
6051 i9xx_set_pipeconf(intel_crtc);
6053 intel_crtc->active = true;
6055 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6057 for_each_encoder_on_crtc(dev, crtc, encoder)
6058 if (encoder->pre_pll_enable)
6059 encoder->pre_pll_enable(encoder);
6062 if (IS_CHERRYVIEW(dev))
6063 chv_enable_pll(intel_crtc, intel_crtc->config);
6065 vlv_enable_pll(intel_crtc, intel_crtc->config);
6068 for_each_encoder_on_crtc(dev, crtc, encoder)
6069 if (encoder->pre_enable)
6070 encoder->pre_enable(encoder);
6072 i9xx_pfit_enable(intel_crtc);
6074 intel_crtc_load_lut(crtc);
6076 intel_enable_pipe(intel_crtc);
6078 assert_vblank_disabled(crtc);
6079 drm_crtc_vblank_on(crtc);
6081 for_each_encoder_on_crtc(dev, crtc, encoder)
6082 encoder->enable(encoder);
6085 static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
6087 struct drm_device *dev = crtc->base.dev;
6088 struct drm_i915_private *dev_priv = dev->dev_private;
6090 I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0);
6091 I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1);
6094 static void i9xx_crtc_enable(struct drm_crtc *crtc)
6096 struct drm_device *dev = crtc->dev;
6097 struct drm_i915_private *dev_priv = to_i915(dev);
6098 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6099 struct intel_encoder *encoder;
6100 int pipe = intel_crtc->pipe;
6102 if (WARN_ON(intel_crtc->active))
6105 i9xx_set_pll_dividers(intel_crtc);
6107 if (intel_crtc->config->has_dp_encoder)
6108 intel_dp_set_m_n(intel_crtc, M1_N1);
6110 intel_set_pipe_timings(intel_crtc);
6112 i9xx_set_pipeconf(intel_crtc);
6114 intel_crtc->active = true;
6117 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6119 for_each_encoder_on_crtc(dev, crtc, encoder)
6120 if (encoder->pre_enable)
6121 encoder->pre_enable(encoder);
6123 i9xx_enable_pll(intel_crtc);
6125 i9xx_pfit_enable(intel_crtc);
6127 intel_crtc_load_lut(crtc);
6129 intel_update_watermarks(crtc);
6130 intel_enable_pipe(intel_crtc);
6132 assert_vblank_disabled(crtc);
6133 drm_crtc_vblank_on(crtc);
6135 for_each_encoder_on_crtc(dev, crtc, encoder)
6136 encoder->enable(encoder);
6139 static void i9xx_pfit_disable(struct intel_crtc *crtc)
6141 struct drm_device *dev = crtc->base.dev;
6142 struct drm_i915_private *dev_priv = dev->dev_private;
6144 if (!crtc->config->gmch_pfit.control)
6147 assert_pipe_disabled(dev_priv, crtc->pipe);
6149 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
6150 I915_READ(PFIT_CONTROL));
6151 I915_WRITE(PFIT_CONTROL, 0);
6154 static void i9xx_crtc_disable(struct drm_crtc *crtc)
6156 struct drm_device *dev = crtc->dev;
6157 struct drm_i915_private *dev_priv = dev->dev_private;
6158 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6159 struct intel_encoder *encoder;
6160 int pipe = intel_crtc->pipe;
6163 * On gen2 planes are double buffered but the pipe isn't, so we must
6164 * wait for planes to fully turn off before disabling the pipe.
6165 * We also need to wait on all gmch platforms because of the
6166 * self-refresh mode constraint explained above.
6168 intel_wait_for_vblank(dev, pipe);
6170 for_each_encoder_on_crtc(dev, crtc, encoder)
6171 encoder->disable(encoder);
6173 drm_crtc_vblank_off(crtc);
6174 assert_vblank_disabled(crtc);
6176 intel_disable_pipe(intel_crtc);
6178 i9xx_pfit_disable(intel_crtc);
6180 for_each_encoder_on_crtc(dev, crtc, encoder)
6181 if (encoder->post_disable)
6182 encoder->post_disable(encoder);
6184 if (!intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) {
6185 if (IS_CHERRYVIEW(dev))
6186 chv_disable_pll(dev_priv, pipe);
6187 else if (IS_VALLEYVIEW(dev))
6188 vlv_disable_pll(dev_priv, pipe);
6190 i9xx_disable_pll(intel_crtc);
6194 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6196 intel_crtc->active = false;
6197 intel_update_watermarks(crtc);
6200 static void intel_crtc_disable_noatomic(struct drm_crtc *crtc)
6202 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6203 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6204 enum intel_display_power_domain domain;
6205 unsigned long domains;
6207 if (!intel_crtc->active)
6210 if (to_intel_plane_state(crtc->primary->state)->visible) {
6211 intel_crtc_wait_for_pending_flips(crtc);
6212 intel_pre_disable_primary(crtc);
6215 intel_crtc_disable_planes(crtc, crtc->state->plane_mask);
6216 dev_priv->display.crtc_disable(crtc);
6218 domains = intel_crtc->enabled_power_domains;
6219 for_each_power_domain(domain, domains)
6220 intel_display_power_put(dev_priv, domain);
6221 intel_crtc->enabled_power_domains = 0;
6225 * turn all crtc's off, but do not adjust state
6226 * This has to be paired with a call to intel_modeset_setup_hw_state.
6228 int intel_display_suspend(struct drm_device *dev)
6230 struct drm_mode_config *config = &dev->mode_config;
6231 struct drm_modeset_acquire_ctx *ctx = config->acquire_ctx;
6232 struct drm_atomic_state *state;
6233 struct drm_crtc *crtc;
6234 unsigned crtc_mask = 0;
6240 lockdep_assert_held(&ctx->ww_ctx);
6241 state = drm_atomic_state_alloc(dev);
6242 if (WARN_ON(!state))
6245 state->acquire_ctx = ctx;
6246 state->allow_modeset = true;
6248 for_each_crtc(dev, crtc) {
6249 struct drm_crtc_state *crtc_state =
6250 drm_atomic_get_crtc_state(state, crtc);
6252 ret = PTR_ERR_OR_ZERO(crtc_state);
6256 if (!crtc_state->active)
6259 crtc_state->active = false;
6260 crtc_mask |= 1 << drm_crtc_index(crtc);
6264 ret = intel_set_mode(state);
6267 for_each_crtc(dev, crtc)
6268 if (crtc_mask & (1 << drm_crtc_index(crtc)))
6269 crtc->state->active = true;
6277 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
6278 drm_atomic_state_free(state);
6282 /* Master function to enable/disable CRTC and corresponding power wells */
6283 int intel_crtc_control(struct drm_crtc *crtc, bool enable)
6285 struct drm_device *dev = crtc->dev;
6286 struct drm_mode_config *config = &dev->mode_config;
6287 struct drm_modeset_acquire_ctx *ctx = config->acquire_ctx;
6288 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6289 struct intel_crtc_state *pipe_config;
6290 struct drm_atomic_state *state;
6293 if (enable == intel_crtc->active)
6296 if (enable && !crtc->state->enable)
6299 /* this function should be called with drm_modeset_lock_all for now */
6302 lockdep_assert_held(&ctx->ww_ctx);
6304 state = drm_atomic_state_alloc(dev);
6305 if (WARN_ON(!state))
6308 state->acquire_ctx = ctx;
6309 state->allow_modeset = true;
6311 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
6312 if (IS_ERR(pipe_config)) {
6313 ret = PTR_ERR(pipe_config);
6316 pipe_config->base.active = enable;
6318 ret = intel_set_mode(state);
6323 DRM_ERROR("Updating crtc active failed with %i\n", ret);
6324 drm_atomic_state_free(state);
6329 * Sets the power management mode of the pipe and plane.
6331 void intel_crtc_update_dpms(struct drm_crtc *crtc)
6333 struct drm_device *dev = crtc->dev;
6334 struct intel_encoder *intel_encoder;
6335 bool enable = false;
6337 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
6338 enable |= intel_encoder->connectors_active;
6340 intel_crtc_control(crtc, enable);
6343 void intel_encoder_destroy(struct drm_encoder *encoder)
6345 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6347 drm_encoder_cleanup(encoder);
6348 kfree(intel_encoder);
6351 /* Simple dpms helper for encoders with just one connector, no cloning and only
6352 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
6353 * state of the entire output pipe. */
6354 static void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
6356 if (mode == DRM_MODE_DPMS_ON) {
6357 encoder->connectors_active = true;
6359 intel_crtc_update_dpms(encoder->base.crtc);
6361 encoder->connectors_active = false;
6363 intel_crtc_update_dpms(encoder->base.crtc);
6367 /* Cross check the actual hw state with our own modeset state tracking (and it's
6368 * internal consistency). */
6369 static void intel_connector_check_state(struct intel_connector *connector)
6371 if (connector->get_hw_state(connector)) {
6372 struct intel_encoder *encoder = connector->encoder;
6373 struct drm_crtc *crtc;
6374 bool encoder_enabled;
6377 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6378 connector->base.base.id,
6379 connector->base.name);
6381 /* there is no real hw state for MST connectors */
6382 if (connector->mst_port)
6385 I915_STATE_WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
6386 "wrong connector dpms state\n");
6387 I915_STATE_WARN(connector->base.encoder != &encoder->base,
6388 "active connector not linked to encoder\n");
6391 I915_STATE_WARN(!encoder->connectors_active,
6392 "encoder->connectors_active not set\n");
6394 encoder_enabled = encoder->get_hw_state(encoder, &pipe);
6395 I915_STATE_WARN(!encoder_enabled, "encoder not enabled\n");
6396 if (I915_STATE_WARN_ON(!encoder->base.crtc))
6399 crtc = encoder->base.crtc;
6401 I915_STATE_WARN(!crtc->state->enable,
6402 "crtc not enabled\n");
6403 I915_STATE_WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
6404 I915_STATE_WARN(pipe != to_intel_crtc(crtc)->pipe,
6405 "encoder active on the wrong pipe\n");
6410 int intel_connector_init(struct intel_connector *connector)
6412 struct drm_connector_state *connector_state;
6414 connector_state = kzalloc(sizeof *connector_state, GFP_KERNEL);
6415 if (!connector_state)
6418 connector->base.state = connector_state;
6422 struct intel_connector *intel_connector_alloc(void)
6424 struct intel_connector *connector;
6426 connector = kzalloc(sizeof *connector, GFP_KERNEL);
6430 if (intel_connector_init(connector) < 0) {
6438 /* Even simpler default implementation, if there's really no special case to
6440 void intel_connector_dpms(struct drm_connector *connector, int mode)
6442 /* All the simple cases only support two dpms states. */
6443 if (mode != DRM_MODE_DPMS_ON)
6444 mode = DRM_MODE_DPMS_OFF;
6446 if (mode == connector->dpms)
6449 connector->dpms = mode;
6451 /* Only need to change hw state when actually enabled */
6452 if (connector->encoder)
6453 intel_encoder_dpms(to_intel_encoder(connector->encoder), mode);
6455 intel_modeset_check_state(connector->dev);
6458 /* Simple connector->get_hw_state implementation for encoders that support only
6459 * one connector and no cloning and hence the encoder state determines the state
6460 * of the connector. */
6461 bool intel_connector_get_hw_state(struct intel_connector *connector)
6464 struct intel_encoder *encoder = connector->encoder;
6466 return encoder->get_hw_state(encoder, &pipe);
6469 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
6471 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6472 return crtc_state->fdi_lanes;
6477 static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
6478 struct intel_crtc_state *pipe_config)
6480 struct drm_atomic_state *state = pipe_config->base.state;
6481 struct intel_crtc *other_crtc;
6482 struct intel_crtc_state *other_crtc_state;
6484 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6485 pipe_name(pipe), pipe_config->fdi_lanes);
6486 if (pipe_config->fdi_lanes > 4) {
6487 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6488 pipe_name(pipe), pipe_config->fdi_lanes);
6492 if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
6493 if (pipe_config->fdi_lanes > 2) {
6494 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6495 pipe_config->fdi_lanes);
6502 if (INTEL_INFO(dev)->num_pipes == 2)
6505 /* Ivybridge 3 pipe is really complicated */
6510 if (pipe_config->fdi_lanes <= 2)
6513 other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C));
6515 intel_atomic_get_crtc_state(state, other_crtc);
6516 if (IS_ERR(other_crtc_state))
6517 return PTR_ERR(other_crtc_state);
6519 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
6520 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6521 pipe_name(pipe), pipe_config->fdi_lanes);
6526 if (pipe_config->fdi_lanes > 2) {
6527 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6528 pipe_name(pipe), pipe_config->fdi_lanes);
6532 other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B));
6534 intel_atomic_get_crtc_state(state, other_crtc);
6535 if (IS_ERR(other_crtc_state))
6536 return PTR_ERR(other_crtc_state);
6538 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
6539 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6549 static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
6550 struct intel_crtc_state *pipe_config)
6552 struct drm_device *dev = intel_crtc->base.dev;
6553 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6554 int lane, link_bw, fdi_dotclock, ret;
6555 bool needs_recompute = false;
6558 /* FDI is a binary signal running at ~2.7GHz, encoding
6559 * each output octet as 10 bits. The actual frequency
6560 * is stored as a divider into a 100MHz clock, and the
6561 * mode pixel clock is stored in units of 1KHz.
6562 * Hence the bw of each lane in terms of the mode signal
6565 link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
6567 fdi_dotclock = adjusted_mode->crtc_clock;
6569 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
6570 pipe_config->pipe_bpp);
6572 pipe_config->fdi_lanes = lane;
6574 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
6575 link_bw, &pipe_config->fdi_m_n);
6577 ret = ironlake_check_fdi_lanes(intel_crtc->base.dev,
6578 intel_crtc->pipe, pipe_config);
6579 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
6580 pipe_config->pipe_bpp -= 2*3;
6581 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6582 pipe_config->pipe_bpp);
6583 needs_recompute = true;
6584 pipe_config->bw_constrained = true;
6589 if (needs_recompute)
6595 static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv,
6596 struct intel_crtc_state *pipe_config)
6598 if (pipe_config->pipe_bpp > 24)
6601 /* HSW can handle pixel rate up to cdclk? */
6602 if (IS_HASWELL(dev_priv->dev))
6606 * We compare against max which means we must take
6607 * the increased cdclk requirement into account when
6608 * calculating the new cdclk.
6610 * Should measure whether using a lower cdclk w/o IPS
6612 return ilk_pipe_pixel_rate(pipe_config) <=
6613 dev_priv->max_cdclk_freq * 95 / 100;
6616 static void hsw_compute_ips_config(struct intel_crtc *crtc,
6617 struct intel_crtc_state *pipe_config)
6619 struct drm_device *dev = crtc->base.dev;
6620 struct drm_i915_private *dev_priv = dev->dev_private;
6622 pipe_config->ips_enabled = i915.enable_ips &&
6623 hsw_crtc_supports_ips(crtc) &&
6624 pipe_config_supports_ips(dev_priv, pipe_config);
6627 static int intel_crtc_compute_config(struct intel_crtc *crtc,
6628 struct intel_crtc_state *pipe_config)
6630 struct drm_device *dev = crtc->base.dev;
6631 struct drm_i915_private *dev_priv = dev->dev_private;
6632 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6634 /* FIXME should check pixel clock limits on all platforms */
6635 if (INTEL_INFO(dev)->gen < 4) {
6636 int clock_limit = dev_priv->max_cdclk_freq;
6639 * Enable pixel doubling when the dot clock
6640 * is > 90% of the (display) core speed.
6642 * GDG double wide on either pipe,
6643 * otherwise pipe A only.
6645 if ((crtc->pipe == PIPE_A || IS_I915G(dev)) &&
6646 adjusted_mode->crtc_clock > clock_limit * 9 / 10) {
6648 pipe_config->double_wide = true;
6651 if (adjusted_mode->crtc_clock > clock_limit * 9 / 10)
6656 * Pipe horizontal size must be even in:
6658 * - LVDS dual channel mode
6659 * - Double wide pipe
6661 if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6662 intel_is_dual_link_lvds(dev)) || pipe_config->double_wide)
6663 pipe_config->pipe_src_w &= ~1;
6665 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6666 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6668 if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
6669 adjusted_mode->hsync_start == adjusted_mode->hdisplay)
6673 hsw_compute_ips_config(crtc, pipe_config);
6675 if (pipe_config->has_pch_encoder)
6676 return ironlake_fdi_compute_config(crtc, pipe_config);
6681 static int skylake_get_display_clock_speed(struct drm_device *dev)
6683 struct drm_i915_private *dev_priv = to_i915(dev);
6684 uint32_t lcpll1 = I915_READ(LCPLL1_CTL);
6685 uint32_t cdctl = I915_READ(CDCLK_CTL);
6688 if (!(lcpll1 & LCPLL_PLL_ENABLE))
6689 return 24000; /* 24MHz is the cd freq with NSSC ref */
6691 if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540)
6694 linkrate = (I915_READ(DPLL_CTRL1) &
6695 DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1;
6697 if (linkrate == DPLL_CTRL1_LINK_RATE_2160 ||
6698 linkrate == DPLL_CTRL1_LINK_RATE_1080) {
6700 switch (cdctl & CDCLK_FREQ_SEL_MASK) {
6701 case CDCLK_FREQ_450_432:
6703 case CDCLK_FREQ_337_308:
6705 case CDCLK_FREQ_675_617:
6708 WARN(1, "Unknown cd freq selection\n");
6712 switch (cdctl & CDCLK_FREQ_SEL_MASK) {
6713 case CDCLK_FREQ_450_432:
6715 case CDCLK_FREQ_337_308:
6717 case CDCLK_FREQ_675_617:
6720 WARN(1, "Unknown cd freq selection\n");
6724 /* error case, do as if DPLL0 isn't enabled */
6728 static int broxton_get_display_clock_speed(struct drm_device *dev)
6730 struct drm_i915_private *dev_priv = to_i915(dev);
6731 uint32_t cdctl = I915_READ(CDCLK_CTL);
6732 uint32_t pll_ratio = I915_READ(BXT_DE_PLL_CTL) & BXT_DE_PLL_RATIO_MASK;
6733 uint32_t pll_enab = I915_READ(BXT_DE_PLL_ENABLE);
6736 if (!(pll_enab & BXT_DE_PLL_PLL_ENABLE))
6739 cdclk = 19200 * pll_ratio / 2;
6741 switch (cdctl & BXT_CDCLK_CD2X_DIV_SEL_MASK) {
6742 case BXT_CDCLK_CD2X_DIV_SEL_1:
6743 return cdclk; /* 576MHz or 624MHz */
6744 case BXT_CDCLK_CD2X_DIV_SEL_1_5:
6745 return cdclk * 2 / 3; /* 384MHz */
6746 case BXT_CDCLK_CD2X_DIV_SEL_2:
6747 return cdclk / 2; /* 288MHz */
6748 case BXT_CDCLK_CD2X_DIV_SEL_4:
6749 return cdclk / 4; /* 144MHz */
6752 /* error case, do as if DE PLL isn't enabled */
6756 static int broadwell_get_display_clock_speed(struct drm_device *dev)
6758 struct drm_i915_private *dev_priv = dev->dev_private;
6759 uint32_t lcpll = I915_READ(LCPLL_CTL);
6760 uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
6762 if (lcpll & LCPLL_CD_SOURCE_FCLK)
6764 else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT)
6766 else if (freq == LCPLL_CLK_FREQ_450)
6768 else if (freq == LCPLL_CLK_FREQ_54O_BDW)
6770 else if (freq == LCPLL_CLK_FREQ_337_5_BDW)
6776 static int haswell_get_display_clock_speed(struct drm_device *dev)
6778 struct drm_i915_private *dev_priv = dev->dev_private;
6779 uint32_t lcpll = I915_READ(LCPLL_CTL);
6780 uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
6782 if (lcpll & LCPLL_CD_SOURCE_FCLK)
6784 else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT)
6786 else if (freq == LCPLL_CLK_FREQ_450)
6788 else if (IS_HSW_ULT(dev))
6794 static int valleyview_get_display_clock_speed(struct drm_device *dev)
6796 struct drm_i915_private *dev_priv = dev->dev_private;
6800 if (dev_priv->hpll_freq == 0)
6801 dev_priv->hpll_freq = valleyview_get_vco(dev_priv);
6803 mutex_lock(&dev_priv->sb_lock);
6804 val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
6805 mutex_unlock(&dev_priv->sb_lock);
6807 divider = val & DISPLAY_FREQUENCY_VALUES;
6809 WARN((val & DISPLAY_FREQUENCY_STATUS) !=
6810 (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
6811 "cdclk change in progress\n");
6813 return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1);
6816 static int ilk_get_display_clock_speed(struct drm_device *dev)
6821 static int i945_get_display_clock_speed(struct drm_device *dev)
6826 static int i915_get_display_clock_speed(struct drm_device *dev)
6831 static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
6836 static int pnv_get_display_clock_speed(struct drm_device *dev)
6840 pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
6842 switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
6843 case GC_DISPLAY_CLOCK_267_MHZ_PNV:
6845 case GC_DISPLAY_CLOCK_333_MHZ_PNV:
6847 case GC_DISPLAY_CLOCK_444_MHZ_PNV:
6849 case GC_DISPLAY_CLOCK_200_MHZ_PNV:
6852 DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc);
6853 case GC_DISPLAY_CLOCK_133_MHZ_PNV:
6855 case GC_DISPLAY_CLOCK_167_MHZ_PNV:
6860 static int i915gm_get_display_clock_speed(struct drm_device *dev)
6864 pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
6866 if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
6869 switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
6870 case GC_DISPLAY_CLOCK_333_MHZ:
6873 case GC_DISPLAY_CLOCK_190_200_MHZ:
6879 static int i865_get_display_clock_speed(struct drm_device *dev)
6884 static int i85x_get_display_clock_speed(struct drm_device *dev)
6889 * 852GM/852GMV only supports 133 MHz and the HPLLCC
6890 * encoding is different :(
6891 * FIXME is this the right way to detect 852GM/852GMV?
6893 if (dev->pdev->revision == 0x1)
6896 pci_bus_read_config_word(dev->pdev->bus,
6897 PCI_DEVFN(0, 3), HPLLCC, &hpllcc);
6899 /* Assume that the hardware is in the high speed state. This
6900 * should be the default.
6902 switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
6903 case GC_CLOCK_133_200:
6904 case GC_CLOCK_133_200_2:
6905 case GC_CLOCK_100_200:
6907 case GC_CLOCK_166_250:
6909 case GC_CLOCK_100_133:
6911 case GC_CLOCK_133_266:
6912 case GC_CLOCK_133_266_2:
6913 case GC_CLOCK_166_266:
6917 /* Shouldn't happen */
6921 static int i830_get_display_clock_speed(struct drm_device *dev)
6926 static unsigned int intel_hpll_vco(struct drm_device *dev)
6928 struct drm_i915_private *dev_priv = dev->dev_private;
6929 static const unsigned int blb_vco[8] = {
6936 static const unsigned int pnv_vco[8] = {
6943 static const unsigned int cl_vco[8] = {
6952 static const unsigned int elk_vco[8] = {
6958 static const unsigned int ctg_vco[8] = {
6966 const unsigned int *vco_table;
6970 /* FIXME other chipsets? */
6972 vco_table = ctg_vco;
6973 else if (IS_G4X(dev))
6974 vco_table = elk_vco;
6975 else if (IS_CRESTLINE(dev))
6977 else if (IS_PINEVIEW(dev))
6978 vco_table = pnv_vco;
6979 else if (IS_G33(dev))
6980 vco_table = blb_vco;
6984 tmp = I915_READ(IS_MOBILE(dev) ? HPLLVCO_MOBILE : HPLLVCO);
6986 vco = vco_table[tmp & 0x7];
6988 DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp);
6990 DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco);
6995 static int gm45_get_display_clock_speed(struct drm_device *dev)
6997 unsigned int cdclk_sel, vco = intel_hpll_vco(dev);
7000 pci_read_config_word(dev->pdev, GCFGC, &tmp);
7002 cdclk_sel = (tmp >> 12) & 0x1;
7008 return cdclk_sel ? 333333 : 222222;
7010 return cdclk_sel ? 320000 : 228571;
7012 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp);
7017 static int i965gm_get_display_clock_speed(struct drm_device *dev)
7019 static const uint8_t div_3200[] = { 16, 10, 8 };
7020 static const uint8_t div_4000[] = { 20, 12, 10 };
7021 static const uint8_t div_5333[] = { 24, 16, 14 };
7022 const uint8_t *div_table;
7023 unsigned int cdclk_sel, vco = intel_hpll_vco(dev);
7026 pci_read_config_word(dev->pdev, GCFGC, &tmp);
7028 cdclk_sel = ((tmp >> 8) & 0x1f) - 1;
7030 if (cdclk_sel >= ARRAY_SIZE(div_3200))
7035 div_table = div_3200;
7038 div_table = div_4000;
7041 div_table = div_5333;
7047 return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]);
7050 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp);
7054 static int g33_get_display_clock_speed(struct drm_device *dev)
7056 static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 };
7057 static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 };
7058 static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 };
7059 static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 };
7060 const uint8_t *div_table;
7061 unsigned int cdclk_sel, vco = intel_hpll_vco(dev);
7064 pci_read_config_word(dev->pdev, GCFGC, &tmp);
7066 cdclk_sel = (tmp >> 4) & 0x7;
7068 if (cdclk_sel >= ARRAY_SIZE(div_3200))
7073 div_table = div_3200;
7076 div_table = div_4000;
7079 div_table = div_4800;
7082 div_table = div_5333;
7088 return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]);
7091 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp);
7096 intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
7098 while (*num > DATA_LINK_M_N_MASK ||
7099 *den > DATA_LINK_M_N_MASK) {
7105 static void compute_m_n(unsigned int m, unsigned int n,
7106 uint32_t *ret_m, uint32_t *ret_n)
7108 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
7109 *ret_m = div_u64((uint64_t) m * *ret_n, n);
7110 intel_reduce_m_n_ratio(ret_m, ret_n);
7114 intel_link_compute_m_n(int bits_per_pixel, int nlanes,
7115 int pixel_clock, int link_clock,
7116 struct intel_link_m_n *m_n)
7120 compute_m_n(bits_per_pixel * pixel_clock,
7121 link_clock * nlanes * 8,
7122 &m_n->gmch_m, &m_n->gmch_n);
7124 compute_m_n(pixel_clock, link_clock,
7125 &m_n->link_m, &m_n->link_n);
7128 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
7130 if (i915.panel_use_ssc >= 0)
7131 return i915.panel_use_ssc != 0;
7132 return dev_priv->vbt.lvds_use_ssc
7133 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
7136 static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state,
7139 struct drm_device *dev = crtc_state->base.crtc->dev;
7140 struct drm_i915_private *dev_priv = dev->dev_private;
7143 WARN_ON(!crtc_state->base.state);
7145 if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev)) {
7147 } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7148 intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
7149 refclk = dev_priv->vbt.lvds_ssc_freq;
7150 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7151 } else if (!IS_GEN2(dev)) {
7160 static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
7162 return (1 << dpll->n) << 16 | dpll->m2;
7165 static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
7167 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
7170 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
7171 struct intel_crtc_state *crtc_state,
7172 intel_clock_t *reduced_clock)
7174 struct drm_device *dev = crtc->base.dev;
7177 if (IS_PINEVIEW(dev)) {
7178 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
7180 fp2 = pnv_dpll_compute_fp(reduced_clock);
7182 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
7184 fp2 = i9xx_dpll_compute_fp(reduced_clock);
7187 crtc_state->dpll_hw_state.fp0 = fp;
7189 crtc->lowfreq_avail = false;
7190 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7192 crtc_state->dpll_hw_state.fp1 = fp2;
7193 crtc->lowfreq_avail = true;
7195 crtc_state->dpll_hw_state.fp1 = fp;
7199 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
7205 * PLLB opamp always calibrates to max value of 0x3f, force enable it
7206 * and set it to a reasonable value instead.
7208 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7209 reg_val &= 0xffffff00;
7210 reg_val |= 0x00000030;
7211 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7213 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7214 reg_val &= 0x8cffffff;
7215 reg_val = 0x8c000000;
7216 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7218 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7219 reg_val &= 0xffffff00;
7220 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7222 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7223 reg_val &= 0x00ffffff;
7224 reg_val |= 0xb0000000;
7225 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7228 static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
7229 struct intel_link_m_n *m_n)
7231 struct drm_device *dev = crtc->base.dev;
7232 struct drm_i915_private *dev_priv = dev->dev_private;
7233 int pipe = crtc->pipe;
7235 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7236 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
7237 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
7238 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
7241 static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
7242 struct intel_link_m_n *m_n,
7243 struct intel_link_m_n *m2_n2)
7245 struct drm_device *dev = crtc->base.dev;
7246 struct drm_i915_private *dev_priv = dev->dev_private;
7247 int pipe = crtc->pipe;
7248 enum transcoder transcoder = crtc->config->cpu_transcoder;
7250 if (INTEL_INFO(dev)->gen >= 5) {
7251 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
7252 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
7253 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
7254 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
7255 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
7256 * for gen < 8) and if DRRS is supported (to make sure the
7257 * registers are not unnecessarily accessed).
7259 if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) &&
7260 crtc->config->has_drrs) {
7261 I915_WRITE(PIPE_DATA_M2(transcoder),
7262 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
7263 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
7264 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
7265 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
7268 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7269 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
7270 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
7271 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
7275 void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n)
7277 struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
7280 dp_m_n = &crtc->config->dp_m_n;
7281 dp_m2_n2 = &crtc->config->dp_m2_n2;
7282 } else if (m_n == M2_N2) {
7285 * M2_N2 registers are not supported. Hence m2_n2 divider value
7286 * needs to be programmed into M1_N1.
7288 dp_m_n = &crtc->config->dp_m2_n2;
7290 DRM_ERROR("Unsupported divider value\n");
7294 if (crtc->config->has_pch_encoder)
7295 intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n);
7297 intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2);
7300 static void vlv_compute_dpll(struct intel_crtc *crtc,
7301 struct intel_crtc_state *pipe_config)
7306 * Enable DPIO clock input. We should never disable the reference
7307 * clock for pipe B, since VGA hotplug / manual detection depends
7310 dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REF_CLK_ENABLE_VLV |
7311 DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_REF_CLK_VLV;
7312 /* We should never disable this, set it here for state tracking */
7313 if (crtc->pipe == PIPE_B)
7314 dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7315 dpll |= DPLL_VCO_ENABLE;
7316 pipe_config->dpll_hw_state.dpll = dpll;
7318 dpll_md = (pipe_config->pixel_multiplier - 1)
7319 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7320 pipe_config->dpll_hw_state.dpll_md = dpll_md;
7323 static void vlv_prepare_pll(struct intel_crtc *crtc,
7324 const struct intel_crtc_state *pipe_config)
7326 struct drm_device *dev = crtc->base.dev;
7327 struct drm_i915_private *dev_priv = dev->dev_private;
7328 int pipe = crtc->pipe;
7330 u32 bestn, bestm1, bestm2, bestp1, bestp2;
7331 u32 coreclk, reg_val;
7333 mutex_lock(&dev_priv->sb_lock);
7335 bestn = pipe_config->dpll.n;
7336 bestm1 = pipe_config->dpll.m1;
7337 bestm2 = pipe_config->dpll.m2;
7338 bestp1 = pipe_config->dpll.p1;
7339 bestp2 = pipe_config->dpll.p2;
7341 /* See eDP HDMI DPIO driver vbios notes doc */
7343 /* PLL B needs special handling */
7345 vlv_pllb_recal_opamp(dev_priv, pipe);
7347 /* Set up Tx target for periodic Rcomp update */
7348 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
7350 /* Disable target IRef on PLL */
7351 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
7352 reg_val &= 0x00ffffff;
7353 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
7355 /* Disable fast lock */
7356 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
7358 /* Set idtafcrecal before PLL is enabled */
7359 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
7360 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
7361 mdiv |= ((bestn << DPIO_N_SHIFT));
7362 mdiv |= (1 << DPIO_K_SHIFT);
7365 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7366 * but we don't support that).
7367 * Note: don't use the DAC post divider as it seems unstable.
7369 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
7370 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7372 mdiv |= DPIO_ENABLE_CALIBRATION;
7373 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7375 /* Set HBR and RBR LPF coefficients */
7376 if (pipe_config->port_clock == 162000 ||
7377 intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) ||
7378 intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
7379 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7382 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7385 if (pipe_config->has_dp_encoder) {
7386 /* Use SSC source */
7388 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7391 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7393 } else { /* HDMI or VGA */
7394 /* Use bend source */
7396 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7399 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7403 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
7404 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
7405 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
7406 intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
7407 coreclk |= 0x01000000;
7408 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
7410 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
7411 mutex_unlock(&dev_priv->sb_lock);
7414 static void chv_compute_dpll(struct intel_crtc *crtc,
7415 struct intel_crtc_state *pipe_config)
7417 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
7418 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS |
7420 if (crtc->pipe != PIPE_A)
7421 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7423 pipe_config->dpll_hw_state.dpll_md =
7424 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7427 static void chv_prepare_pll(struct intel_crtc *crtc,
7428 const struct intel_crtc_state *pipe_config)
7430 struct drm_device *dev = crtc->base.dev;
7431 struct drm_i915_private *dev_priv = dev->dev_private;
7432 int pipe = crtc->pipe;
7433 int dpll_reg = DPLL(crtc->pipe);
7434 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7435 u32 loopfilter, tribuf_calcntr;
7436 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
7440 bestn = pipe_config->dpll.n;
7441 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
7442 bestm1 = pipe_config->dpll.m1;
7443 bestm2 = pipe_config->dpll.m2 >> 22;
7444 bestp1 = pipe_config->dpll.p1;
7445 bestp2 = pipe_config->dpll.p2;
7446 vco = pipe_config->dpll.vco;
7451 * Enable Refclk and SSC
7453 I915_WRITE(dpll_reg,
7454 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
7456 mutex_lock(&dev_priv->sb_lock);
7458 /* p1 and p2 divider */
7459 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
7460 5 << DPIO_CHV_S1_DIV_SHIFT |
7461 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
7462 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
7463 1 << DPIO_CHV_K_DIV_SHIFT);
7465 /* Feedback post-divider - m2 */
7466 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7468 /* Feedback refclk divider - n and m1 */
7469 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7470 DPIO_CHV_M1_DIV_BY_2 |
7471 1 << DPIO_CHV_N_DIV_SHIFT);
7473 /* M2 fraction division */
7475 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
7477 /* M2 fraction division enable */
7478 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7479 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7480 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7482 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7483 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
7485 /* Program digital lock detect threshold */
7486 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7487 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7488 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7489 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7491 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7492 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7495 if (vco == 5400000) {
7496 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7497 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7498 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7499 tribuf_calcntr = 0x9;
7500 } else if (vco <= 6200000) {
7501 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7502 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7503 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7504 tribuf_calcntr = 0x9;
7505 } else if (vco <= 6480000) {
7506 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7507 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7508 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7509 tribuf_calcntr = 0x8;
7511 /* Not supported. Apply the same limits as in the max case */
7512 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7513 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7514 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7517 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7519 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
7520 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7521 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7522 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7525 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7526 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7529 mutex_unlock(&dev_priv->sb_lock);
7533 * vlv_force_pll_on - forcibly enable just the PLL
7534 * @dev_priv: i915 private structure
7535 * @pipe: pipe PLL to enable
7536 * @dpll: PLL configuration
7538 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7539 * in cases where we need the PLL enabled even when @pipe is not going to
7542 void vlv_force_pll_on(struct drm_device *dev, enum pipe pipe,
7543 const struct dpll *dpll)
7545 struct intel_crtc *crtc =
7546 to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe));
7547 struct intel_crtc_state pipe_config = {
7548 .base.crtc = &crtc->base,
7549 .pixel_multiplier = 1,
7553 if (IS_CHERRYVIEW(dev)) {
7554 chv_compute_dpll(crtc, &pipe_config);
7555 chv_prepare_pll(crtc, &pipe_config);
7556 chv_enable_pll(crtc, &pipe_config);
7558 vlv_compute_dpll(crtc, &pipe_config);
7559 vlv_prepare_pll(crtc, &pipe_config);
7560 vlv_enable_pll(crtc, &pipe_config);
7565 * vlv_force_pll_off - forcibly disable just the PLL
7566 * @dev_priv: i915 private structure
7567 * @pipe: pipe PLL to disable
7569 * Disable the PLL for @pipe. To be used in cases where we need
7570 * the PLL enabled even when @pipe is not going to be enabled.
7572 void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe)
7574 if (IS_CHERRYVIEW(dev))
7575 chv_disable_pll(to_i915(dev), pipe);
7577 vlv_disable_pll(to_i915(dev), pipe);
7580 static void i9xx_compute_dpll(struct intel_crtc *crtc,
7581 struct intel_crtc_state *crtc_state,
7582 intel_clock_t *reduced_clock,
7585 struct drm_device *dev = crtc->base.dev;
7586 struct drm_i915_private *dev_priv = dev->dev_private;
7589 struct dpll *clock = &crtc_state->dpll;
7591 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7593 is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) ||
7594 intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI);
7596 dpll = DPLL_VGA_MODE_DIS;
7598 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS))
7599 dpll |= DPLLB_MODE_LVDS;
7601 dpll |= DPLLB_MODE_DAC_SERIAL;
7603 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
7604 dpll |= (crtc_state->pixel_multiplier - 1)
7605 << SDVO_MULTIPLIER_SHIFT_HIRES;
7609 dpll |= DPLL_SDVO_HIGH_SPEED;
7611 if (crtc_state->has_dp_encoder)
7612 dpll |= DPLL_SDVO_HIGH_SPEED;
7614 /* compute bitmask from p1 value */
7615 if (IS_PINEVIEW(dev))
7616 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
7618 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7619 if (IS_G4X(dev) && reduced_clock)
7620 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
7622 switch (clock->p2) {
7624 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
7627 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
7630 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
7633 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
7636 if (INTEL_INFO(dev)->gen >= 4)
7637 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
7639 if (crtc_state->sdvo_tv_clock)
7640 dpll |= PLL_REF_INPUT_TVCLKINBC;
7641 else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7642 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
7643 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7645 dpll |= PLL_REF_INPUT_DREFCLK;
7647 dpll |= DPLL_VCO_ENABLE;
7648 crtc_state->dpll_hw_state.dpll = dpll;
7650 if (INTEL_INFO(dev)->gen >= 4) {
7651 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
7652 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7653 crtc_state->dpll_hw_state.dpll_md = dpll_md;
7657 static void i8xx_compute_dpll(struct intel_crtc *crtc,
7658 struct intel_crtc_state *crtc_state,
7659 intel_clock_t *reduced_clock,
7662 struct drm_device *dev = crtc->base.dev;
7663 struct drm_i915_private *dev_priv = dev->dev_private;
7665 struct dpll *clock = &crtc_state->dpll;
7667 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7669 dpll = DPLL_VGA_MODE_DIS;
7671 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7672 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7675 dpll |= PLL_P1_DIVIDE_BY_TWO;
7677 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7679 dpll |= PLL_P2_DIVIDE_BY_4;
7682 if (!IS_I830(dev) && intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO))
7683 dpll |= DPLL_DVO_2X_MODE;
7685 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7686 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
7687 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7689 dpll |= PLL_REF_INPUT_DREFCLK;
7691 dpll |= DPLL_VCO_ENABLE;
7692 crtc_state->dpll_hw_state.dpll = dpll;
7695 static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
7697 struct drm_device *dev = intel_crtc->base.dev;
7698 struct drm_i915_private *dev_priv = dev->dev_private;
7699 enum pipe pipe = intel_crtc->pipe;
7700 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
7701 struct drm_display_mode *adjusted_mode =
7702 &intel_crtc->config->base.adjusted_mode;
7703 uint32_t crtc_vtotal, crtc_vblank_end;
7706 /* We need to be careful not to changed the adjusted mode, for otherwise
7707 * the hw state checker will get angry at the mismatch. */
7708 crtc_vtotal = adjusted_mode->crtc_vtotal;
7709 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
7711 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
7712 /* the chip adds 2 halflines automatically */
7714 crtc_vblank_end -= 1;
7716 if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO))
7717 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
7719 vsyncshift = adjusted_mode->crtc_hsync_start -
7720 adjusted_mode->crtc_htotal / 2;
7722 vsyncshift += adjusted_mode->crtc_htotal;
7725 if (INTEL_INFO(dev)->gen > 3)
7726 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
7728 I915_WRITE(HTOTAL(cpu_transcoder),
7729 (adjusted_mode->crtc_hdisplay - 1) |
7730 ((adjusted_mode->crtc_htotal - 1) << 16));
7731 I915_WRITE(HBLANK(cpu_transcoder),
7732 (adjusted_mode->crtc_hblank_start - 1) |
7733 ((adjusted_mode->crtc_hblank_end - 1) << 16));
7734 I915_WRITE(HSYNC(cpu_transcoder),
7735 (adjusted_mode->crtc_hsync_start - 1) |
7736 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7738 I915_WRITE(VTOTAL(cpu_transcoder),
7739 (adjusted_mode->crtc_vdisplay - 1) |
7740 ((crtc_vtotal - 1) << 16));
7741 I915_WRITE(VBLANK(cpu_transcoder),
7742 (adjusted_mode->crtc_vblank_start - 1) |
7743 ((crtc_vblank_end - 1) << 16));
7744 I915_WRITE(VSYNC(cpu_transcoder),
7745 (adjusted_mode->crtc_vsync_start - 1) |
7746 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7748 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7749 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7750 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7752 if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
7753 (pipe == PIPE_B || pipe == PIPE_C))
7754 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7756 /* pipesrc controls the size that is scaled from, which should
7757 * always be the user's requested size.
7759 I915_WRITE(PIPESRC(pipe),
7760 ((intel_crtc->config->pipe_src_w - 1) << 16) |
7761 (intel_crtc->config->pipe_src_h - 1));
7764 static void intel_get_pipe_timings(struct intel_crtc *crtc,
7765 struct intel_crtc_state *pipe_config)
7767 struct drm_device *dev = crtc->base.dev;
7768 struct drm_i915_private *dev_priv = dev->dev_private;
7769 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
7772 tmp = I915_READ(HTOTAL(cpu_transcoder));
7773 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7774 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
7775 tmp = I915_READ(HBLANK(cpu_transcoder));
7776 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7777 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
7778 tmp = I915_READ(HSYNC(cpu_transcoder));
7779 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7780 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
7782 tmp = I915_READ(VTOTAL(cpu_transcoder));
7783 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7784 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
7785 tmp = I915_READ(VBLANK(cpu_transcoder));
7786 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7787 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
7788 tmp = I915_READ(VSYNC(cpu_transcoder));
7789 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7790 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
7792 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
7793 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7794 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7795 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
7798 tmp = I915_READ(PIPESRC(crtc->pipe));
7799 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7800 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7802 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7803 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
7806 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
7807 struct intel_crtc_state *pipe_config)
7809 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7810 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7811 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7812 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
7814 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7815 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7816 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7817 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
7819 mode->flags = pipe_config->base.adjusted_mode.flags;
7821 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
7822 mode->flags |= pipe_config->base.adjusted_mode.flags;
7825 static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
7827 struct drm_device *dev = intel_crtc->base.dev;
7828 struct drm_i915_private *dev_priv = dev->dev_private;
7833 if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
7834 (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
7835 pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE;
7837 if (intel_crtc->config->double_wide)
7838 pipeconf |= PIPECONF_DOUBLE_WIDE;
7840 /* only g4x and later have fancy bpc/dither controls */
7841 if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
7842 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7843 if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30)
7844 pipeconf |= PIPECONF_DITHER_EN |
7845 PIPECONF_DITHER_TYPE_SP;
7847 switch (intel_crtc->config->pipe_bpp) {
7849 pipeconf |= PIPECONF_6BPC;
7852 pipeconf |= PIPECONF_8BPC;
7855 pipeconf |= PIPECONF_10BPC;
7858 /* Case prevented by intel_choose_pipe_bpp_dither. */
7863 if (HAS_PIPE_CXSR(dev)) {
7864 if (intel_crtc->lowfreq_avail) {
7865 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
7866 pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
7868 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
7872 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
7873 if (INTEL_INFO(dev)->gen < 4 ||
7874 intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO))
7875 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7877 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7879 pipeconf |= PIPECONF_PROGRESSIVE;
7881 if (IS_VALLEYVIEW(dev) && intel_crtc->config->limited_color_range)
7882 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
7884 I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
7885 POSTING_READ(PIPECONF(intel_crtc->pipe));
7888 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7889 struct intel_crtc_state *crtc_state)
7891 struct drm_device *dev = crtc->base.dev;
7892 struct drm_i915_private *dev_priv = dev->dev_private;
7893 int refclk, num_connectors = 0;
7894 intel_clock_t clock;
7896 bool is_dsi = false;
7897 struct intel_encoder *encoder;
7898 const intel_limit_t *limit;
7899 struct drm_atomic_state *state = crtc_state->base.state;
7900 struct drm_connector *connector;
7901 struct drm_connector_state *connector_state;
7904 memset(&crtc_state->dpll_hw_state, 0,
7905 sizeof(crtc_state->dpll_hw_state));
7907 for_each_connector_in_state(state, connector, connector_state, i) {
7908 if (connector_state->crtc != &crtc->base)
7911 encoder = to_intel_encoder(connector_state->best_encoder);
7913 switch (encoder->type) {
7914 case INTEL_OUTPUT_DSI:
7927 if (!crtc_state->clock_set) {
7928 refclk = i9xx_get_refclk(crtc_state, num_connectors);
7931 * Returns a set of divisors for the desired target clock with
7932 * the given refclk, or FALSE. The returned values represent
7933 * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
7936 limit = intel_limit(crtc_state, refclk);
7937 ok = dev_priv->display.find_dpll(limit, crtc_state,
7938 crtc_state->port_clock,
7939 refclk, NULL, &clock);
7941 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7945 /* Compat-code for transition, will disappear. */
7946 crtc_state->dpll.n = clock.n;
7947 crtc_state->dpll.m1 = clock.m1;
7948 crtc_state->dpll.m2 = clock.m2;
7949 crtc_state->dpll.p1 = clock.p1;
7950 crtc_state->dpll.p2 = clock.p2;
7954 i8xx_compute_dpll(crtc, crtc_state, NULL,
7956 } else if (IS_CHERRYVIEW(dev)) {
7957 chv_compute_dpll(crtc, crtc_state);
7958 } else if (IS_VALLEYVIEW(dev)) {
7959 vlv_compute_dpll(crtc, crtc_state);
7961 i9xx_compute_dpll(crtc, crtc_state, NULL,
7968 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
7969 struct intel_crtc_state *pipe_config)
7971 struct drm_device *dev = crtc->base.dev;
7972 struct drm_i915_private *dev_priv = dev->dev_private;
7975 if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev)))
7978 tmp = I915_READ(PFIT_CONTROL);
7979 if (!(tmp & PFIT_ENABLE))
7982 /* Check whether the pfit is attached to our pipe. */
7983 if (INTEL_INFO(dev)->gen < 4) {
7984 if (crtc->pipe != PIPE_B)
7987 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7991 pipe_config->gmch_pfit.control = tmp;
7992 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
7993 if (INTEL_INFO(dev)->gen < 5)
7994 pipe_config->gmch_pfit.lvds_border_bits =
7995 I915_READ(LVDS) & LVDS_BORDER_ENABLE;
7998 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
7999 struct intel_crtc_state *pipe_config)
8001 struct drm_device *dev = crtc->base.dev;
8002 struct drm_i915_private *dev_priv = dev->dev_private;
8003 int pipe = pipe_config->cpu_transcoder;
8004 intel_clock_t clock;
8006 int refclk = 100000;
8008 /* In case of MIPI DPLL will not even be used */
8009 if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE))
8012 mutex_lock(&dev_priv->sb_lock);
8013 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
8014 mutex_unlock(&dev_priv->sb_lock);
8016 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
8017 clock.m2 = mdiv & DPIO_M2DIV_MASK;
8018 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
8019 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
8020 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
8022 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
8026 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
8027 struct intel_initial_plane_config *plane_config)
8029 struct drm_device *dev = crtc->base.dev;
8030 struct drm_i915_private *dev_priv = dev->dev_private;
8031 u32 val, base, offset;
8032 int pipe = crtc->pipe, plane = crtc->plane;
8033 int fourcc, pixel_format;
8034 unsigned int aligned_height;
8035 struct drm_framebuffer *fb;
8036 struct intel_framebuffer *intel_fb;
8038 val = I915_READ(DSPCNTR(plane));
8039 if (!(val & DISPLAY_PLANE_ENABLE))
8042 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8044 DRM_DEBUG_KMS("failed to alloc fb\n");
8048 fb = &intel_fb->base;
8050 if (INTEL_INFO(dev)->gen >= 4) {
8051 if (val & DISPPLANE_TILED) {
8052 plane_config->tiling = I915_TILING_X;
8053 fb->modifier[0] = I915_FORMAT_MOD_X_TILED;
8057 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
8058 fourcc = i9xx_format_to_fourcc(pixel_format);
8059 fb->pixel_format = fourcc;
8060 fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8;
8062 if (INTEL_INFO(dev)->gen >= 4) {
8063 if (plane_config->tiling)
8064 offset = I915_READ(DSPTILEOFF(plane));
8066 offset = I915_READ(DSPLINOFF(plane));
8067 base = I915_READ(DSPSURF(plane)) & 0xfffff000;
8069 base = I915_READ(DSPADDR(plane));
8071 plane_config->base = base;
8073 val = I915_READ(PIPESRC(pipe));
8074 fb->width = ((val >> 16) & 0xfff) + 1;
8075 fb->height = ((val >> 0) & 0xfff) + 1;
8077 val = I915_READ(DSPSTRIDE(pipe));
8078 fb->pitches[0] = val & 0xffffffc0;
8080 aligned_height = intel_fb_align_height(dev, fb->height,
8084 plane_config->size = fb->pitches[0] * aligned_height;
8086 DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8087 pipe_name(pipe), plane, fb->width, fb->height,
8088 fb->bits_per_pixel, base, fb->pitches[0],
8089 plane_config->size);
8091 plane_config->fb = intel_fb;
8094 static void chv_crtc_clock_get(struct intel_crtc *crtc,
8095 struct intel_crtc_state *pipe_config)
8097 struct drm_device *dev = crtc->base.dev;
8098 struct drm_i915_private *dev_priv = dev->dev_private;
8099 int pipe = pipe_config->cpu_transcoder;
8100 enum dpio_channel port = vlv_pipe_to_channel(pipe);
8101 intel_clock_t clock;
8102 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2;
8103 int refclk = 100000;
8105 mutex_lock(&dev_priv->sb_lock);
8106 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
8107 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
8108 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
8109 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
8110 mutex_unlock(&dev_priv->sb_lock);
8112 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
8113 clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff);
8114 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
8115 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
8116 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
8118 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
8121 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
8122 struct intel_crtc_state *pipe_config)
8124 struct drm_device *dev = crtc->base.dev;
8125 struct drm_i915_private *dev_priv = dev->dev_private;
8128 if (!intel_display_power_is_enabled(dev_priv,
8129 POWER_DOMAIN_PIPE(crtc->pipe)))
8132 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
8133 pipe_config->shared_dpll = DPLL_ID_PRIVATE;
8135 tmp = I915_READ(PIPECONF(crtc->pipe));
8136 if (!(tmp & PIPECONF_ENABLE))
8139 if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
8140 switch (tmp & PIPECONF_BPC_MASK) {
8142 pipe_config->pipe_bpp = 18;
8145 pipe_config->pipe_bpp = 24;
8147 case PIPECONF_10BPC:
8148 pipe_config->pipe_bpp = 30;
8155 if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT))
8156 pipe_config->limited_color_range = true;
8158 if (INTEL_INFO(dev)->gen < 4)
8159 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
8161 intel_get_pipe_timings(crtc, pipe_config);
8163 i9xx_get_pfit_config(crtc, pipe_config);
8165 if (INTEL_INFO(dev)->gen >= 4) {
8166 tmp = I915_READ(DPLL_MD(crtc->pipe));
8167 pipe_config->pixel_multiplier =
8168 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
8169 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
8170 pipe_config->dpll_hw_state.dpll_md = tmp;
8171 } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
8172 tmp = I915_READ(DPLL(crtc->pipe));
8173 pipe_config->pixel_multiplier =
8174 ((tmp & SDVO_MULTIPLIER_MASK)
8175 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
8177 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8178 * port and will be fixed up in the encoder->get_config
8180 pipe_config->pixel_multiplier = 1;
8182 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
8183 if (!IS_VALLEYVIEW(dev)) {
8185 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
8186 * on 830. Filter it out here so that we don't
8187 * report errors due to that.
8190 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
8192 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
8193 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
8195 /* Mask out read-only status bits. */
8196 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
8197 DPLL_PORTC_READY_MASK |
8198 DPLL_PORTB_READY_MASK);
8201 if (IS_CHERRYVIEW(dev))
8202 chv_crtc_clock_get(crtc, pipe_config);
8203 else if (IS_VALLEYVIEW(dev))
8204 vlv_crtc_clock_get(crtc, pipe_config);
8206 i9xx_crtc_clock_get(crtc, pipe_config);
8211 static void ironlake_init_pch_refclk(struct drm_device *dev)
8213 struct drm_i915_private *dev_priv = dev->dev_private;
8214 struct intel_encoder *encoder;
8216 bool has_lvds = false;
8217 bool has_cpu_edp = false;
8218 bool has_panel = false;
8219 bool has_ck505 = false;
8220 bool can_ssc = false;
8222 /* We need to take the global config into account */
8223 for_each_intel_encoder(dev, encoder) {
8224 switch (encoder->type) {
8225 case INTEL_OUTPUT_LVDS:
8229 case INTEL_OUTPUT_EDP:
8231 if (enc_to_dig_port(&encoder->base)->port == PORT_A)
8239 if (HAS_PCH_IBX(dev)) {
8240 has_ck505 = dev_priv->vbt.display_clock_mode;
8241 can_ssc = has_ck505;
8247 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
8248 has_panel, has_lvds, has_ck505);
8250 /* Ironlake: try to setup display ref clock before DPLL
8251 * enabling. This is only under driver's control after
8252 * PCH B stepping, previous chipset stepping should be
8253 * ignoring this setting.
8255 val = I915_READ(PCH_DREF_CONTROL);
8257 /* As we must carefully and slowly disable/enable each source in turn,
8258 * compute the final state we want first and check if we need to
8259 * make any changes at all.
8262 final &= ~DREF_NONSPREAD_SOURCE_MASK;
8264 final |= DREF_NONSPREAD_CK505_ENABLE;
8266 final |= DREF_NONSPREAD_SOURCE_ENABLE;
8268 final &= ~DREF_SSC_SOURCE_MASK;
8269 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8270 final &= ~DREF_SSC1_ENABLE;
8273 final |= DREF_SSC_SOURCE_ENABLE;
8275 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8276 final |= DREF_SSC1_ENABLE;
8279 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8280 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8282 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8284 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8286 final |= DREF_SSC_SOURCE_DISABLE;
8287 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8293 /* Always enable nonspread source */
8294 val &= ~DREF_NONSPREAD_SOURCE_MASK;
8297 val |= DREF_NONSPREAD_CK505_ENABLE;
8299 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8302 val &= ~DREF_SSC_SOURCE_MASK;
8303 val |= DREF_SSC_SOURCE_ENABLE;
8305 /* SSC must be turned on before enabling the CPU output */
8306 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8307 DRM_DEBUG_KMS("Using SSC on panel\n");
8308 val |= DREF_SSC1_ENABLE;
8310 val &= ~DREF_SSC1_ENABLE;
8312 /* Get SSC going before enabling the outputs */
8313 I915_WRITE(PCH_DREF_CONTROL, val);
8314 POSTING_READ(PCH_DREF_CONTROL);
8317 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8319 /* Enable CPU source on CPU attached eDP */
8321 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8322 DRM_DEBUG_KMS("Using SSC on eDP\n");
8323 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8325 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8327 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8329 I915_WRITE(PCH_DREF_CONTROL, val);
8330 POSTING_READ(PCH_DREF_CONTROL);
8333 DRM_DEBUG_KMS("Disabling SSC entirely\n");
8335 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8337 /* Turn off CPU output */
8338 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8340 I915_WRITE(PCH_DREF_CONTROL, val);
8341 POSTING_READ(PCH_DREF_CONTROL);
8344 /* Turn off the SSC source */
8345 val &= ~DREF_SSC_SOURCE_MASK;
8346 val |= DREF_SSC_SOURCE_DISABLE;
8349 val &= ~DREF_SSC1_ENABLE;
8351 I915_WRITE(PCH_DREF_CONTROL, val);
8352 POSTING_READ(PCH_DREF_CONTROL);
8356 BUG_ON(val != final);
8359 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
8363 tmp = I915_READ(SOUTH_CHICKEN2);
8364 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
8365 I915_WRITE(SOUTH_CHICKEN2, tmp);
8367 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
8368 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
8369 DRM_ERROR("FDI mPHY reset assert timeout\n");
8371 tmp = I915_READ(SOUTH_CHICKEN2);
8372 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
8373 I915_WRITE(SOUTH_CHICKEN2, tmp);
8375 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
8376 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
8377 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
8380 /* WaMPhyProgramming:hsw */
8381 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
8385 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
8386 tmp &= ~(0xFF << 24);
8387 tmp |= (0x12 << 24);
8388 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
8390 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
8392 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
8394 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
8396 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
8398 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
8399 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8400 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
8402 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
8403 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8404 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
8406 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
8409 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
8411 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
8414 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
8416 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
8419 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
8421 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
8424 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
8426 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
8427 tmp &= ~(0xFF << 16);
8428 tmp |= (0x1C << 16);
8429 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
8431 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
8432 tmp &= ~(0xFF << 16);
8433 tmp |= (0x1C << 16);
8434 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
8436 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
8438 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
8440 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
8442 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
8444 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
8445 tmp &= ~(0xF << 28);
8447 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
8449 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
8450 tmp &= ~(0xF << 28);
8452 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
8455 /* Implements 3 different sequences from BSpec chapter "Display iCLK
8456 * Programming" based on the parameters passed:
8457 * - Sequence to enable CLKOUT_DP
8458 * - Sequence to enable CLKOUT_DP without spread
8459 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8461 static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread,
8464 struct drm_i915_private *dev_priv = dev->dev_private;
8467 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
8469 if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE &&
8470 with_fdi, "LP PCH doesn't have FDI\n"))
8473 mutex_lock(&dev_priv->sb_lock);
8475 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8476 tmp &= ~SBI_SSCCTL_DISABLE;
8477 tmp |= SBI_SSCCTL_PATHALT;
8478 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8483 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8484 tmp &= ~SBI_SSCCTL_PATHALT;
8485 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8488 lpt_reset_fdi_mphy(dev_priv);
8489 lpt_program_fdi_mphy(dev_priv);
8493 reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
8494 SBI_GEN0 : SBI_DBUFF0;
8495 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8496 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8497 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8499 mutex_unlock(&dev_priv->sb_lock);
8502 /* Sequence to disable CLKOUT_DP */
8503 static void lpt_disable_clkout_dp(struct drm_device *dev)
8505 struct drm_i915_private *dev_priv = dev->dev_private;
8508 mutex_lock(&dev_priv->sb_lock);
8510 reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
8511 SBI_GEN0 : SBI_DBUFF0;
8512 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8513 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8514 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8516 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8517 if (!(tmp & SBI_SSCCTL_DISABLE)) {
8518 if (!(tmp & SBI_SSCCTL_PATHALT)) {
8519 tmp |= SBI_SSCCTL_PATHALT;
8520 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8523 tmp |= SBI_SSCCTL_DISABLE;
8524 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8527 mutex_unlock(&dev_priv->sb_lock);
8530 static void lpt_init_pch_refclk(struct drm_device *dev)
8532 struct intel_encoder *encoder;
8533 bool has_vga = false;
8535 for_each_intel_encoder(dev, encoder) {
8536 switch (encoder->type) {
8537 case INTEL_OUTPUT_ANALOG:
8546 lpt_enable_clkout_dp(dev, true, true);
8548 lpt_disable_clkout_dp(dev);
8552 * Initialize reference clocks when the driver loads
8554 void intel_init_pch_refclk(struct drm_device *dev)
8556 if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
8557 ironlake_init_pch_refclk(dev);
8558 else if (HAS_PCH_LPT(dev))
8559 lpt_init_pch_refclk(dev);
8562 static int ironlake_get_refclk(struct intel_crtc_state *crtc_state)
8564 struct drm_device *dev = crtc_state->base.crtc->dev;
8565 struct drm_i915_private *dev_priv = dev->dev_private;
8566 struct drm_atomic_state *state = crtc_state->base.state;
8567 struct drm_connector *connector;
8568 struct drm_connector_state *connector_state;
8569 struct intel_encoder *encoder;
8570 int num_connectors = 0, i;
8571 bool is_lvds = false;
8573 for_each_connector_in_state(state, connector, connector_state, i) {
8574 if (connector_state->crtc != crtc_state->base.crtc)
8577 encoder = to_intel_encoder(connector_state->best_encoder);
8579 switch (encoder->type) {
8580 case INTEL_OUTPUT_LVDS:
8589 if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
8590 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8591 dev_priv->vbt.lvds_ssc_freq);
8592 return dev_priv->vbt.lvds_ssc_freq;
8598 static void ironlake_set_pipeconf(struct drm_crtc *crtc)
8600 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
8601 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8602 int pipe = intel_crtc->pipe;
8607 switch (intel_crtc->config->pipe_bpp) {
8609 val |= PIPECONF_6BPC;
8612 val |= PIPECONF_8BPC;
8615 val |= PIPECONF_10BPC;
8618 val |= PIPECONF_12BPC;
8621 /* Case prevented by intel_choose_pipe_bpp_dither. */
8625 if (intel_crtc->config->dither)
8626 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8628 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8629 val |= PIPECONF_INTERLACED_ILK;
8631 val |= PIPECONF_PROGRESSIVE;
8633 if (intel_crtc->config->limited_color_range)
8634 val |= PIPECONF_COLOR_RANGE_SELECT;
8636 I915_WRITE(PIPECONF(pipe), val);
8637 POSTING_READ(PIPECONF(pipe));
8641 * Set up the pipe CSC unit.
8643 * Currently only full range RGB to limited range RGB conversion
8644 * is supported, but eventually this should handle various
8645 * RGB<->YCbCr scenarios as well.
8647 static void intel_set_pipe_csc(struct drm_crtc *crtc)
8649 struct drm_device *dev = crtc->dev;
8650 struct drm_i915_private *dev_priv = dev->dev_private;
8651 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8652 int pipe = intel_crtc->pipe;
8653 uint16_t coeff = 0x7800; /* 1.0 */
8656 * TODO: Check what kind of values actually come out of the pipe
8657 * with these coeff/postoff values and adjust to get the best
8658 * accuracy. Perhaps we even need to take the bpc value into
8662 if (intel_crtc->config->limited_color_range)
8663 coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
8666 * GY/GU and RY/RU should be the other way around according
8667 * to BSpec, but reality doesn't agree. Just set them up in
8668 * a way that results in the correct picture.
8670 I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16);
8671 I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0);
8673 I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff);
8674 I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0);
8676 I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0);
8677 I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16);
8679 I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0);
8680 I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0);
8681 I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
8683 if (INTEL_INFO(dev)->gen > 6) {
8684 uint16_t postoff = 0;
8686 if (intel_crtc->config->limited_color_range)
8687 postoff = (16 * (1 << 12) / 255) & 0x1fff;
8689 I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
8690 I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
8691 I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
8693 I915_WRITE(PIPE_CSC_MODE(pipe), 0);
8695 uint32_t mode = CSC_MODE_YUV_TO_RGB;
8697 if (intel_crtc->config->limited_color_range)
8698 mode |= CSC_BLACK_SCREEN_OFFSET;
8700 I915_WRITE(PIPE_CSC_MODE(pipe), mode);
8704 static void haswell_set_pipeconf(struct drm_crtc *crtc)
8706 struct drm_device *dev = crtc->dev;
8707 struct drm_i915_private *dev_priv = dev->dev_private;
8708 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8709 enum pipe pipe = intel_crtc->pipe;
8710 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
8715 if (IS_HASWELL(dev) && intel_crtc->config->dither)
8716 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8718 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8719 val |= PIPECONF_INTERLACED_ILK;
8721 val |= PIPECONF_PROGRESSIVE;
8723 I915_WRITE(PIPECONF(cpu_transcoder), val);
8724 POSTING_READ(PIPECONF(cpu_transcoder));
8726 I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT);
8727 POSTING_READ(GAMMA_MODE(intel_crtc->pipe));
8729 if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) {
8732 switch (intel_crtc->config->pipe_bpp) {
8734 val |= PIPEMISC_DITHER_6_BPC;
8737 val |= PIPEMISC_DITHER_8_BPC;
8740 val |= PIPEMISC_DITHER_10_BPC;
8743 val |= PIPEMISC_DITHER_12_BPC;
8746 /* Case prevented by pipe_config_set_bpp. */
8750 if (intel_crtc->config->dither)
8751 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8753 I915_WRITE(PIPEMISC(pipe), val);
8757 static bool ironlake_compute_clocks(struct drm_crtc *crtc,
8758 struct intel_crtc_state *crtc_state,
8759 intel_clock_t *clock,
8760 bool *has_reduced_clock,
8761 intel_clock_t *reduced_clock)
8763 struct drm_device *dev = crtc->dev;
8764 struct drm_i915_private *dev_priv = dev->dev_private;
8766 const intel_limit_t *limit;
8769 refclk = ironlake_get_refclk(crtc_state);
8772 * Returns a set of divisors for the desired target clock with the given
8773 * refclk, or FALSE. The returned values represent the clock equation:
8774 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
8776 limit = intel_limit(crtc_state, refclk);
8777 ret = dev_priv->display.find_dpll(limit, crtc_state,
8778 crtc_state->port_clock,
8779 refclk, NULL, clock);
8786 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8789 * Account for spread spectrum to avoid
8790 * oversubscribing the link. Max center spread
8791 * is 2.5%; use 5% for safety's sake.
8793 u32 bps = target_clock * bpp * 21 / 20;
8794 return DIV_ROUND_UP(bps, link_bw * 8);
8797 static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
8799 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
8802 static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8803 struct intel_crtc_state *crtc_state,
8805 intel_clock_t *reduced_clock, u32 *fp2)
8807 struct drm_crtc *crtc = &intel_crtc->base;
8808 struct drm_device *dev = crtc->dev;
8809 struct drm_i915_private *dev_priv = dev->dev_private;
8810 struct drm_atomic_state *state = crtc_state->base.state;
8811 struct drm_connector *connector;
8812 struct drm_connector_state *connector_state;
8813 struct intel_encoder *encoder;
8815 int factor, num_connectors = 0, i;
8816 bool is_lvds = false, is_sdvo = false;
8818 for_each_connector_in_state(state, connector, connector_state, i) {
8819 if (connector_state->crtc != crtc_state->base.crtc)
8822 encoder = to_intel_encoder(connector_state->best_encoder);
8824 switch (encoder->type) {
8825 case INTEL_OUTPUT_LVDS:
8828 case INTEL_OUTPUT_SDVO:
8829 case INTEL_OUTPUT_HDMI:
8839 /* Enable autotuning of the PLL clock (if permissible) */
8842 if ((intel_panel_use_ssc(dev_priv) &&
8843 dev_priv->vbt.lvds_ssc_freq == 100000) ||
8844 (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev)))
8846 } else if (crtc_state->sdvo_tv_clock)
8849 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8852 if (fp2 && (reduced_clock->m < factor * reduced_clock->n))
8858 dpll |= DPLLB_MODE_LVDS;
8860 dpll |= DPLLB_MODE_DAC_SERIAL;
8862 dpll |= (crtc_state->pixel_multiplier - 1)
8863 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
8866 dpll |= DPLL_SDVO_HIGH_SPEED;
8867 if (crtc_state->has_dp_encoder)
8868 dpll |= DPLL_SDVO_HIGH_SPEED;
8870 /* compute bitmask from p1 value */
8871 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8873 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8875 switch (crtc_state->dpll.p2) {
8877 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8880 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8883 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8886 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8890 if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
8891 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8893 dpll |= PLL_REF_INPUT_DREFCLK;
8895 return dpll | DPLL_VCO_ENABLE;
8898 static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8899 struct intel_crtc_state *crtc_state)
8901 struct drm_device *dev = crtc->base.dev;
8902 intel_clock_t clock, reduced_clock;
8903 u32 dpll = 0, fp = 0, fp2 = 0;
8904 bool ok, has_reduced_clock = false;
8905 bool is_lvds = false;
8906 struct intel_shared_dpll *pll;
8908 memset(&crtc_state->dpll_hw_state, 0,
8909 sizeof(crtc_state->dpll_hw_state));
8911 is_lvds = intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS);
8913 WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
8914 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
8916 ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock,
8917 &has_reduced_clock, &reduced_clock);
8918 if (!ok && !crtc_state->clock_set) {
8919 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8922 /* Compat-code for transition, will disappear. */
8923 if (!crtc_state->clock_set) {
8924 crtc_state->dpll.n = clock.n;
8925 crtc_state->dpll.m1 = clock.m1;
8926 crtc_state->dpll.m2 = clock.m2;
8927 crtc_state->dpll.p1 = clock.p1;
8928 crtc_state->dpll.p2 = clock.p2;
8931 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8932 if (crtc_state->has_pch_encoder) {
8933 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
8934 if (has_reduced_clock)
8935 fp2 = i9xx_dpll_compute_fp(&reduced_clock);
8937 dpll = ironlake_compute_dpll(crtc, crtc_state,
8938 &fp, &reduced_clock,
8939 has_reduced_clock ? &fp2 : NULL);
8941 crtc_state->dpll_hw_state.dpll = dpll;
8942 crtc_state->dpll_hw_state.fp0 = fp;
8943 if (has_reduced_clock)
8944 crtc_state->dpll_hw_state.fp1 = fp2;
8946 crtc_state->dpll_hw_state.fp1 = fp;
8948 pll = intel_get_shared_dpll(crtc, crtc_state);
8950 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8951 pipe_name(crtc->pipe));
8956 if (is_lvds && has_reduced_clock)
8957 crtc->lowfreq_avail = true;
8959 crtc->lowfreq_avail = false;
8964 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8965 struct intel_link_m_n *m_n)
8967 struct drm_device *dev = crtc->base.dev;
8968 struct drm_i915_private *dev_priv = dev->dev_private;
8969 enum pipe pipe = crtc->pipe;
8971 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
8972 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
8973 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
8975 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
8976 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
8977 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8980 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8981 enum transcoder transcoder,
8982 struct intel_link_m_n *m_n,
8983 struct intel_link_m_n *m2_n2)
8985 struct drm_device *dev = crtc->base.dev;
8986 struct drm_i915_private *dev_priv = dev->dev_private;
8987 enum pipe pipe = crtc->pipe;
8989 if (INTEL_INFO(dev)->gen >= 5) {
8990 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
8991 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
8992 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
8994 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
8995 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
8996 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8997 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8998 * gen < 8) and if DRRS is supported (to make sure the
8999 * registers are not unnecessarily read).
9001 if (m2_n2 && INTEL_INFO(dev)->gen < 8 &&
9002 crtc->config->has_drrs) {
9003 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
9004 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
9005 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
9007 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
9008 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
9009 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9012 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
9013 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
9014 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
9016 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
9017 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
9018 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9022 void intel_dp_get_m_n(struct intel_crtc *crtc,
9023 struct intel_crtc_state *pipe_config)
9025 if (pipe_config->has_pch_encoder)
9026 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
9028 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
9029 &pipe_config->dp_m_n,
9030 &pipe_config->dp_m2_n2);
9033 static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
9034 struct intel_crtc_state *pipe_config)
9036 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
9037 &pipe_config->fdi_m_n, NULL);
9040 static void skylake_get_pfit_config(struct intel_crtc *crtc,
9041 struct intel_crtc_state *pipe_config)
9043 struct drm_device *dev = crtc->base.dev;
9044 struct drm_i915_private *dev_priv = dev->dev_private;
9045 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
9046 uint32_t ps_ctrl = 0;
9050 /* find scaler attached to this pipe */
9051 for (i = 0; i < crtc->num_scalers; i++) {
9052 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
9053 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
9055 pipe_config->pch_pfit.enabled = true;
9056 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
9057 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
9062 scaler_state->scaler_id = id;
9064 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
9066 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
9071 skylake_get_initial_plane_config(struct intel_crtc *crtc,
9072 struct intel_initial_plane_config *plane_config)
9074 struct drm_device *dev = crtc->base.dev;
9075 struct drm_i915_private *dev_priv = dev->dev_private;
9076 u32 val, base, offset, stride_mult, tiling;
9077 int pipe = crtc->pipe;
9078 int fourcc, pixel_format;
9079 unsigned int aligned_height;
9080 struct drm_framebuffer *fb;
9081 struct intel_framebuffer *intel_fb;
9083 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
9085 DRM_DEBUG_KMS("failed to alloc fb\n");
9089 fb = &intel_fb->base;
9091 val = I915_READ(PLANE_CTL(pipe, 0));
9092 if (!(val & PLANE_CTL_ENABLE))
9095 pixel_format = val & PLANE_CTL_FORMAT_MASK;
9096 fourcc = skl_format_to_fourcc(pixel_format,
9097 val & PLANE_CTL_ORDER_RGBX,
9098 val & PLANE_CTL_ALPHA_MASK);
9099 fb->pixel_format = fourcc;
9100 fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8;
9102 tiling = val & PLANE_CTL_TILED_MASK;
9104 case PLANE_CTL_TILED_LINEAR:
9105 fb->modifier[0] = DRM_FORMAT_MOD_NONE;
9107 case PLANE_CTL_TILED_X:
9108 plane_config->tiling = I915_TILING_X;
9109 fb->modifier[0] = I915_FORMAT_MOD_X_TILED;
9111 case PLANE_CTL_TILED_Y:
9112 fb->modifier[0] = I915_FORMAT_MOD_Y_TILED;
9114 case PLANE_CTL_TILED_YF:
9115 fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED;
9118 MISSING_CASE(tiling);
9122 base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000;
9123 plane_config->base = base;
9125 offset = I915_READ(PLANE_OFFSET(pipe, 0));
9127 val = I915_READ(PLANE_SIZE(pipe, 0));
9128 fb->height = ((val >> 16) & 0xfff) + 1;
9129 fb->width = ((val >> 0) & 0x1fff) + 1;
9131 val = I915_READ(PLANE_STRIDE(pipe, 0));
9132 stride_mult = intel_fb_stride_alignment(dev, fb->modifier[0],
9134 fb->pitches[0] = (val & 0x3ff) * stride_mult;
9136 aligned_height = intel_fb_align_height(dev, fb->height,
9140 plane_config->size = fb->pitches[0] * aligned_height;
9142 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9143 pipe_name(pipe), fb->width, fb->height,
9144 fb->bits_per_pixel, base, fb->pitches[0],
9145 plane_config->size);
9147 plane_config->fb = intel_fb;
9154 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
9155 struct intel_crtc_state *pipe_config)
9157 struct drm_device *dev = crtc->base.dev;
9158 struct drm_i915_private *dev_priv = dev->dev_private;
9161 tmp = I915_READ(PF_CTL(crtc->pipe));
9163 if (tmp & PF_ENABLE) {
9164 pipe_config->pch_pfit.enabled = true;
9165 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
9166 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
9168 /* We currently do not free assignements of panel fitters on
9169 * ivb/hsw (since we don't use the higher upscaling modes which
9170 * differentiates them) so just WARN about this case for now. */
9172 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
9173 PF_PIPE_SEL_IVB(crtc->pipe));
9179 ironlake_get_initial_plane_config(struct intel_crtc *crtc,
9180 struct intel_initial_plane_config *plane_config)
9182 struct drm_device *dev = crtc->base.dev;
9183 struct drm_i915_private *dev_priv = dev->dev_private;
9184 u32 val, base, offset;
9185 int pipe = crtc->pipe;
9186 int fourcc, pixel_format;
9187 unsigned int aligned_height;
9188 struct drm_framebuffer *fb;
9189 struct intel_framebuffer *intel_fb;
9191 val = I915_READ(DSPCNTR(pipe));
9192 if (!(val & DISPLAY_PLANE_ENABLE))
9195 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
9197 DRM_DEBUG_KMS("failed to alloc fb\n");
9201 fb = &intel_fb->base;
9203 if (INTEL_INFO(dev)->gen >= 4) {
9204 if (val & DISPPLANE_TILED) {
9205 plane_config->tiling = I915_TILING_X;
9206 fb->modifier[0] = I915_FORMAT_MOD_X_TILED;
9210 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
9211 fourcc = i9xx_format_to_fourcc(pixel_format);
9212 fb->pixel_format = fourcc;
9213 fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8;
9215 base = I915_READ(DSPSURF(pipe)) & 0xfffff000;
9216 if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
9217 offset = I915_READ(DSPOFFSET(pipe));
9219 if (plane_config->tiling)
9220 offset = I915_READ(DSPTILEOFF(pipe));
9222 offset = I915_READ(DSPLINOFF(pipe));
9224 plane_config->base = base;
9226 val = I915_READ(PIPESRC(pipe));
9227 fb->width = ((val >> 16) & 0xfff) + 1;
9228 fb->height = ((val >> 0) & 0xfff) + 1;
9230 val = I915_READ(DSPSTRIDE(pipe));
9231 fb->pitches[0] = val & 0xffffffc0;
9233 aligned_height = intel_fb_align_height(dev, fb->height,
9237 plane_config->size = fb->pitches[0] * aligned_height;
9239 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9240 pipe_name(pipe), fb->width, fb->height,
9241 fb->bits_per_pixel, base, fb->pitches[0],
9242 plane_config->size);
9244 plane_config->fb = intel_fb;
9247 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
9248 struct intel_crtc_state *pipe_config)
9250 struct drm_device *dev = crtc->base.dev;
9251 struct drm_i915_private *dev_priv = dev->dev_private;
9254 if (!intel_display_power_is_enabled(dev_priv,
9255 POWER_DOMAIN_PIPE(crtc->pipe)))
9258 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9259 pipe_config->shared_dpll = DPLL_ID_PRIVATE;
9261 tmp = I915_READ(PIPECONF(crtc->pipe));
9262 if (!(tmp & PIPECONF_ENABLE))
9265 switch (tmp & PIPECONF_BPC_MASK) {
9267 pipe_config->pipe_bpp = 18;
9270 pipe_config->pipe_bpp = 24;
9272 case PIPECONF_10BPC:
9273 pipe_config->pipe_bpp = 30;
9275 case PIPECONF_12BPC:
9276 pipe_config->pipe_bpp = 36;
9282 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
9283 pipe_config->limited_color_range = true;
9285 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
9286 struct intel_shared_dpll *pll;
9288 pipe_config->has_pch_encoder = true;
9290 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
9291 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9292 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9294 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9296 if (HAS_PCH_IBX(dev_priv->dev)) {
9297 pipe_config->shared_dpll =
9298 (enum intel_dpll_id) crtc->pipe;
9300 tmp = I915_READ(PCH_DPLL_SEL);
9301 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
9302 pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B;
9304 pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A;
9307 pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
9309 WARN_ON(!pll->get_hw_state(dev_priv, pll,
9310 &pipe_config->dpll_hw_state));
9312 tmp = pipe_config->dpll_hw_state.dpll;
9313 pipe_config->pixel_multiplier =
9314 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
9315 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
9317 ironlake_pch_clock_get(crtc, pipe_config);
9319 pipe_config->pixel_multiplier = 1;
9322 intel_get_pipe_timings(crtc, pipe_config);
9324 ironlake_get_pfit_config(crtc, pipe_config);
9329 static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
9331 struct drm_device *dev = dev_priv->dev;
9332 struct intel_crtc *crtc;
9334 for_each_intel_crtc(dev, crtc)
9335 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
9336 pipe_name(crtc->pipe));
9338 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n");
9339 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
9340 I915_STATE_WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
9341 I915_STATE_WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
9342 I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n");
9343 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
9344 "CPU PWM1 enabled\n");
9345 if (IS_HASWELL(dev))
9346 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
9347 "CPU PWM2 enabled\n");
9348 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
9349 "PCH PWM1 enabled\n");
9350 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
9351 "Utility pin enabled\n");
9352 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
9355 * In theory we can still leave IRQs enabled, as long as only the HPD
9356 * interrupts remain enabled. We used to check for that, but since it's
9357 * gen-specific and since we only disable LCPLL after we fully disable
9358 * the interrupts, the check below should be enough.
9360 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
9363 static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
9365 struct drm_device *dev = dev_priv->dev;
9367 if (IS_HASWELL(dev))
9368 return I915_READ(D_COMP_HSW);
9370 return I915_READ(D_COMP_BDW);
9373 static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
9375 struct drm_device *dev = dev_priv->dev;
9377 if (IS_HASWELL(dev)) {
9378 mutex_lock(&dev_priv->rps.hw_lock);
9379 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
9381 DRM_ERROR("Failed to write to D_COMP\n");
9382 mutex_unlock(&dev_priv->rps.hw_lock);
9384 I915_WRITE(D_COMP_BDW, val);
9385 POSTING_READ(D_COMP_BDW);
9390 * This function implements pieces of two sequences from BSpec:
9391 * - Sequence for display software to disable LCPLL
9392 * - Sequence for display software to allow package C8+
9393 * The steps implemented here are just the steps that actually touch the LCPLL
9394 * register. Callers should take care of disabling all the display engine
9395 * functions, doing the mode unset, fixing interrupts, etc.
9397 static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
9398 bool switch_to_fclk, bool allow_power_down)
9402 assert_can_disable_lcpll(dev_priv);
9404 val = I915_READ(LCPLL_CTL);
9406 if (switch_to_fclk) {
9407 val |= LCPLL_CD_SOURCE_FCLK;
9408 I915_WRITE(LCPLL_CTL, val);
9410 if (wait_for_atomic_us(I915_READ(LCPLL_CTL) &
9411 LCPLL_CD_SOURCE_FCLK_DONE, 1))
9412 DRM_ERROR("Switching to FCLK failed\n");
9414 val = I915_READ(LCPLL_CTL);
9417 val |= LCPLL_PLL_DISABLE;
9418 I915_WRITE(LCPLL_CTL, val);
9419 POSTING_READ(LCPLL_CTL);
9421 if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1))
9422 DRM_ERROR("LCPLL still locked\n");
9424 val = hsw_read_dcomp(dev_priv);
9425 val |= D_COMP_COMP_DISABLE;
9426 hsw_write_dcomp(dev_priv, val);
9429 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
9431 DRM_ERROR("D_COMP RCOMP still in progress\n");
9433 if (allow_power_down) {
9434 val = I915_READ(LCPLL_CTL);
9435 val |= LCPLL_POWER_DOWN_ALLOW;
9436 I915_WRITE(LCPLL_CTL, val);
9437 POSTING_READ(LCPLL_CTL);
9442 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9445 static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
9449 val = I915_READ(LCPLL_CTL);
9451 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
9452 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
9456 * Make sure we're not on PC8 state before disabling PC8, otherwise
9457 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
9459 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
9461 if (val & LCPLL_POWER_DOWN_ALLOW) {
9462 val &= ~LCPLL_POWER_DOWN_ALLOW;
9463 I915_WRITE(LCPLL_CTL, val);
9464 POSTING_READ(LCPLL_CTL);
9467 val = hsw_read_dcomp(dev_priv);
9468 val |= D_COMP_COMP_FORCE;
9469 val &= ~D_COMP_COMP_DISABLE;
9470 hsw_write_dcomp(dev_priv, val);
9472 val = I915_READ(LCPLL_CTL);
9473 val &= ~LCPLL_PLL_DISABLE;
9474 I915_WRITE(LCPLL_CTL, val);
9476 if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5))
9477 DRM_ERROR("LCPLL not locked yet\n");
9479 if (val & LCPLL_CD_SOURCE_FCLK) {
9480 val = I915_READ(LCPLL_CTL);
9481 val &= ~LCPLL_CD_SOURCE_FCLK;
9482 I915_WRITE(LCPLL_CTL, val);
9484 if (wait_for_atomic_us((I915_READ(LCPLL_CTL) &
9485 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
9486 DRM_ERROR("Switching back to LCPLL failed\n");
9489 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
9490 intel_update_cdclk(dev_priv->dev);
9494 * Package states C8 and deeper are really deep PC states that can only be
9495 * reached when all the devices on the system allow it, so even if the graphics
9496 * device allows PC8+, it doesn't mean the system will actually get to these
9497 * states. Our driver only allows PC8+ when going into runtime PM.
9499 * The requirements for PC8+ are that all the outputs are disabled, the power
9500 * well is disabled and most interrupts are disabled, and these are also
9501 * requirements for runtime PM. When these conditions are met, we manually do
9502 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9503 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9506 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9507 * the state of some registers, so when we come back from PC8+ we need to
9508 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9509 * need to take care of the registers kept by RC6. Notice that this happens even
9510 * if we don't put the device in PCI D3 state (which is what currently happens
9511 * because of the runtime PM support).
9513 * For more, read "Display Sequences for Package C8" on the hardware
9516 void hsw_enable_pc8(struct drm_i915_private *dev_priv)
9518 struct drm_device *dev = dev_priv->dev;
9521 DRM_DEBUG_KMS("Enabling package C8+\n");
9523 if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
9524 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9525 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
9526 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9529 lpt_disable_clkout_dp(dev);
9530 hsw_disable_lcpll(dev_priv, true, true);
9533 void hsw_disable_pc8(struct drm_i915_private *dev_priv)
9535 struct drm_device *dev = dev_priv->dev;
9538 DRM_DEBUG_KMS("Disabling package C8+\n");
9540 hsw_restore_lcpll(dev_priv);
9541 lpt_init_pch_refclk(dev);
9543 if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
9544 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9545 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
9546 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9549 intel_prepare_ddi(dev);
9552 static void broxton_modeset_commit_cdclk(struct drm_atomic_state *old_state)
9554 struct drm_device *dev = old_state->dev;
9555 unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk;
9557 broxton_set_cdclk(dev, req_cdclk);
9560 /* compute the max rate for new configuration */
9561 static int ilk_max_pixel_rate(struct drm_atomic_state *state)
9563 struct intel_crtc *intel_crtc;
9564 struct intel_crtc_state *crtc_state;
9565 int max_pixel_rate = 0;
9567 for_each_intel_crtc(state->dev, intel_crtc) {
9570 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
9571 if (IS_ERR(crtc_state))
9572 return PTR_ERR(crtc_state);
9574 if (!crtc_state->base.enable)
9577 pixel_rate = ilk_pipe_pixel_rate(crtc_state);
9579 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
9580 if (IS_BROADWELL(state->dev) && crtc_state->ips_enabled)
9581 pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95);
9583 max_pixel_rate = max(max_pixel_rate, pixel_rate);
9586 return max_pixel_rate;
9589 static void broadwell_set_cdclk(struct drm_device *dev, int cdclk)
9591 struct drm_i915_private *dev_priv = dev->dev_private;
9595 if (WARN((I915_READ(LCPLL_CTL) &
9596 (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK |
9597 LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE |
9598 LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW |
9599 LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK,
9600 "trying to change cdclk frequency with cdclk not enabled\n"))
9603 mutex_lock(&dev_priv->rps.hw_lock);
9604 ret = sandybridge_pcode_write(dev_priv,
9605 BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0);
9606 mutex_unlock(&dev_priv->rps.hw_lock);
9608 DRM_ERROR("failed to inform pcode about cdclk change\n");
9612 val = I915_READ(LCPLL_CTL);
9613 val |= LCPLL_CD_SOURCE_FCLK;
9614 I915_WRITE(LCPLL_CTL, val);
9616 if (wait_for_atomic_us(I915_READ(LCPLL_CTL) &
9617 LCPLL_CD_SOURCE_FCLK_DONE, 1))
9618 DRM_ERROR("Switching to FCLK failed\n");
9620 val = I915_READ(LCPLL_CTL);
9621 val &= ~LCPLL_CLK_FREQ_MASK;
9625 val |= LCPLL_CLK_FREQ_450;
9629 val |= LCPLL_CLK_FREQ_54O_BDW;
9633 val |= LCPLL_CLK_FREQ_337_5_BDW;
9637 val |= LCPLL_CLK_FREQ_675_BDW;
9641 WARN(1, "invalid cdclk frequency\n");
9645 I915_WRITE(LCPLL_CTL, val);
9647 val = I915_READ(LCPLL_CTL);
9648 val &= ~LCPLL_CD_SOURCE_FCLK;
9649 I915_WRITE(LCPLL_CTL, val);
9651 if (wait_for_atomic_us((I915_READ(LCPLL_CTL) &
9652 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
9653 DRM_ERROR("Switching back to LCPLL failed\n");
9655 mutex_lock(&dev_priv->rps.hw_lock);
9656 sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data);
9657 mutex_unlock(&dev_priv->rps.hw_lock);
9659 intel_update_cdclk(dev);
9661 WARN(cdclk != dev_priv->cdclk_freq,
9662 "cdclk requested %d kHz but got %d kHz\n",
9663 cdclk, dev_priv->cdclk_freq);
9666 static int broadwell_modeset_calc_cdclk(struct drm_atomic_state *state)
9668 struct drm_i915_private *dev_priv = to_i915(state->dev);
9669 int max_pixclk = ilk_max_pixel_rate(state);
9673 * FIXME should also account for plane ratio
9674 * once 64bpp pixel formats are supported.
9676 if (max_pixclk > 540000)
9678 else if (max_pixclk > 450000)
9680 else if (max_pixclk > 337500)
9686 * FIXME move the cdclk caclulation to
9687 * compute_config() so we can fail gracegully.
9689 if (cdclk > dev_priv->max_cdclk_freq) {
9690 DRM_ERROR("requested cdclk (%d kHz) exceeds max (%d kHz)\n",
9691 cdclk, dev_priv->max_cdclk_freq);
9692 cdclk = dev_priv->max_cdclk_freq;
9695 to_intel_atomic_state(state)->cdclk = cdclk;
9700 static void broadwell_modeset_commit_cdclk(struct drm_atomic_state *old_state)
9702 struct drm_device *dev = old_state->dev;
9703 unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk;
9705 broadwell_set_cdclk(dev, req_cdclk);
9708 static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
9709 struct intel_crtc_state *crtc_state)
9711 if (!intel_ddi_pll_select(crtc, crtc_state))
9714 crtc->lowfreq_avail = false;
9719 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
9721 struct intel_crtc_state *pipe_config)
9725 pipe_config->ddi_pll_sel = SKL_DPLL0;
9726 pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1;
9729 pipe_config->ddi_pll_sel = SKL_DPLL1;
9730 pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2;
9733 pipe_config->ddi_pll_sel = SKL_DPLL2;
9734 pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3;
9737 DRM_ERROR("Incorrect port type\n");
9741 static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
9743 struct intel_crtc_state *pipe_config)
9745 u32 temp, dpll_ctl1;
9747 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
9748 pipe_config->ddi_pll_sel = temp >> (port * 3 + 1);
9750 switch (pipe_config->ddi_pll_sel) {
9753 * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part
9754 * of the shared DPLL framework and thus needs to be read out
9757 dpll_ctl1 = I915_READ(DPLL_CTRL1);
9758 pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f;
9761 pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1;
9764 pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2;
9767 pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3;
9772 static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
9774 struct intel_crtc_state *pipe_config)
9776 pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
9778 switch (pipe_config->ddi_pll_sel) {
9779 case PORT_CLK_SEL_WRPLL1:
9780 pipe_config->shared_dpll = DPLL_ID_WRPLL1;
9782 case PORT_CLK_SEL_WRPLL2:
9783 pipe_config->shared_dpll = DPLL_ID_WRPLL2;
9788 static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
9789 struct intel_crtc_state *pipe_config)
9791 struct drm_device *dev = crtc->base.dev;
9792 struct drm_i915_private *dev_priv = dev->dev_private;
9793 struct intel_shared_dpll *pll;
9797 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9799 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9801 if (IS_SKYLAKE(dev))
9802 skylake_get_ddi_pll(dev_priv, port, pipe_config);
9803 else if (IS_BROXTON(dev))
9804 bxt_get_ddi_pll(dev_priv, port, pipe_config);
9806 haswell_get_ddi_pll(dev_priv, port, pipe_config);
9808 if (pipe_config->shared_dpll >= 0) {
9809 pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
9811 WARN_ON(!pll->get_hw_state(dev_priv, pll,
9812 &pipe_config->dpll_hw_state));
9816 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9817 * DDI E. So just check whether this pipe is wired to DDI E and whether
9818 * the PCH transcoder is on.
9820 if (INTEL_INFO(dev)->gen < 9 &&
9821 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
9822 pipe_config->has_pch_encoder = true;
9824 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9825 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9826 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9828 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9832 static bool haswell_get_pipe_config(struct intel_crtc *crtc,
9833 struct intel_crtc_state *pipe_config)
9835 struct drm_device *dev = crtc->base.dev;
9836 struct drm_i915_private *dev_priv = dev->dev_private;
9837 enum intel_display_power_domain pfit_domain;
9840 if (!intel_display_power_is_enabled(dev_priv,
9841 POWER_DOMAIN_PIPE(crtc->pipe)))
9844 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9845 pipe_config->shared_dpll = DPLL_ID_PRIVATE;
9847 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
9848 if (tmp & TRANS_DDI_FUNC_ENABLE) {
9849 enum pipe trans_edp_pipe;
9850 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9852 WARN(1, "unknown pipe linked to edp transcoder\n");
9853 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9854 case TRANS_DDI_EDP_INPUT_A_ON:
9855 trans_edp_pipe = PIPE_A;
9857 case TRANS_DDI_EDP_INPUT_B_ONOFF:
9858 trans_edp_pipe = PIPE_B;
9860 case TRANS_DDI_EDP_INPUT_C_ONOFF:
9861 trans_edp_pipe = PIPE_C;
9865 if (trans_edp_pipe == crtc->pipe)
9866 pipe_config->cpu_transcoder = TRANSCODER_EDP;
9869 if (!intel_display_power_is_enabled(dev_priv,
9870 POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
9873 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9874 if (!(tmp & PIPECONF_ENABLE))
9877 haswell_get_ddi_port_state(crtc, pipe_config);
9879 intel_get_pipe_timings(crtc, pipe_config);
9881 if (INTEL_INFO(dev)->gen >= 9) {
9882 skl_init_scalers(dev, crtc, pipe_config);
9885 pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9887 if (INTEL_INFO(dev)->gen >= 9) {
9888 pipe_config->scaler_state.scaler_id = -1;
9889 pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX);
9892 if (intel_display_power_is_enabled(dev_priv, pfit_domain)) {
9893 if (INTEL_INFO(dev)->gen == 9)
9894 skylake_get_pfit_config(crtc, pipe_config);
9895 else if (INTEL_INFO(dev)->gen < 9)
9896 ironlake_get_pfit_config(crtc, pipe_config);
9898 MISSING_CASE(INTEL_INFO(dev)->gen);
9901 if (IS_HASWELL(dev))
9902 pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) &&
9903 (I915_READ(IPS_CTL) & IPS_ENABLE);
9905 if (pipe_config->cpu_transcoder != TRANSCODER_EDP) {
9906 pipe_config->pixel_multiplier =
9907 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9909 pipe_config->pixel_multiplier = 1;
9915 static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
9917 struct drm_device *dev = crtc->dev;
9918 struct drm_i915_private *dev_priv = dev->dev_private;
9919 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
9920 uint32_t cntl = 0, size = 0;
9923 unsigned int width = intel_crtc->base.cursor->state->crtc_w;
9924 unsigned int height = intel_crtc->base.cursor->state->crtc_h;
9925 unsigned int stride = roundup_pow_of_two(width) * 4;
9929 WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
9940 cntl |= CURSOR_ENABLE |
9941 CURSOR_GAMMA_ENABLE |
9942 CURSOR_FORMAT_ARGB |
9943 CURSOR_STRIDE(stride);
9945 size = (height << 12) | width;
9948 if (intel_crtc->cursor_cntl != 0 &&
9949 (intel_crtc->cursor_base != base ||
9950 intel_crtc->cursor_size != size ||
9951 intel_crtc->cursor_cntl != cntl)) {
9952 /* On these chipsets we can only modify the base/size/stride
9953 * whilst the cursor is disabled.
9955 I915_WRITE(_CURACNTR, 0);
9956 POSTING_READ(_CURACNTR);
9957 intel_crtc->cursor_cntl = 0;
9960 if (intel_crtc->cursor_base != base) {
9961 I915_WRITE(_CURABASE, base);
9962 intel_crtc->cursor_base = base;
9965 if (intel_crtc->cursor_size != size) {
9966 I915_WRITE(CURSIZE, size);
9967 intel_crtc->cursor_size = size;
9970 if (intel_crtc->cursor_cntl != cntl) {
9971 I915_WRITE(_CURACNTR, cntl);
9972 POSTING_READ(_CURACNTR);
9973 intel_crtc->cursor_cntl = cntl;
9977 static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
9979 struct drm_device *dev = crtc->dev;
9980 struct drm_i915_private *dev_priv = dev->dev_private;
9981 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
9982 int pipe = intel_crtc->pipe;
9987 cntl = MCURSOR_GAMMA_ENABLE;
9988 switch (intel_crtc->base.cursor->state->crtc_w) {
9990 cntl |= CURSOR_MODE_64_ARGB_AX;
9993 cntl |= CURSOR_MODE_128_ARGB_AX;
9996 cntl |= CURSOR_MODE_256_ARGB_AX;
9999 MISSING_CASE(intel_crtc->base.cursor->state->crtc_w);
10002 cntl |= pipe << 28; /* Connect to correct pipe */
10004 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
10005 cntl |= CURSOR_PIPE_CSC_ENABLE;
10008 if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180))
10009 cntl |= CURSOR_ROTATE_180;
10011 if (intel_crtc->cursor_cntl != cntl) {
10012 I915_WRITE(CURCNTR(pipe), cntl);
10013 POSTING_READ(CURCNTR(pipe));
10014 intel_crtc->cursor_cntl = cntl;
10017 /* and commit changes on next vblank */
10018 I915_WRITE(CURBASE(pipe), base);
10019 POSTING_READ(CURBASE(pipe));
10021 intel_crtc->cursor_base = base;
10024 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
10025 static void intel_crtc_update_cursor(struct drm_crtc *crtc,
10028 struct drm_device *dev = crtc->dev;
10029 struct drm_i915_private *dev_priv = dev->dev_private;
10030 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10031 int pipe = intel_crtc->pipe;
10032 int x = crtc->cursor_x;
10033 int y = crtc->cursor_y;
10034 u32 base = 0, pos = 0;
10037 base = intel_crtc->cursor_addr;
10039 if (x >= intel_crtc->config->pipe_src_w)
10042 if (y >= intel_crtc->config->pipe_src_h)
10046 if (x + intel_crtc->base.cursor->state->crtc_w <= 0)
10049 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
10052 pos |= x << CURSOR_X_SHIFT;
10055 if (y + intel_crtc->base.cursor->state->crtc_h <= 0)
10058 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
10061 pos |= y << CURSOR_Y_SHIFT;
10063 if (base == 0 && intel_crtc->cursor_base == 0)
10066 I915_WRITE(CURPOS(pipe), pos);
10068 /* ILK+ do this automagically */
10069 if (HAS_GMCH_DISPLAY(dev) &&
10070 crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) {
10071 base += (intel_crtc->base.cursor->state->crtc_h *
10072 intel_crtc->base.cursor->state->crtc_w - 1) * 4;
10075 if (IS_845G(dev) || IS_I865G(dev))
10076 i845_update_cursor(crtc, base);
10078 i9xx_update_cursor(crtc, base);
10081 static bool cursor_size_ok(struct drm_device *dev,
10082 uint32_t width, uint32_t height)
10084 if (width == 0 || height == 0)
10088 * 845g/865g are special in that they are only limited by
10089 * the width of their cursors, the height is arbitrary up to
10090 * the precision of the register. Everything else requires
10091 * square cursors, limited to a few power-of-two sizes.
10093 if (IS_845G(dev) || IS_I865G(dev)) {
10094 if ((width & 63) != 0)
10097 if (width > (IS_845G(dev) ? 64 : 512))
10103 switch (width | height) {
10118 static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
10119 u16 *blue, uint32_t start, uint32_t size)
10121 int end = (start + size > 256) ? 256 : start + size, i;
10122 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10124 for (i = start; i < end; i++) {
10125 intel_crtc->lut_r[i] = red[i] >> 8;
10126 intel_crtc->lut_g[i] = green[i] >> 8;
10127 intel_crtc->lut_b[i] = blue[i] >> 8;
10130 intel_crtc_load_lut(crtc);
10133 /* VESA 640x480x72Hz mode to set on the pipe */
10134 static struct drm_display_mode load_detect_mode = {
10135 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
10136 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
10139 struct drm_framebuffer *
10140 __intel_framebuffer_create(struct drm_device *dev,
10141 struct drm_mode_fb_cmd2 *mode_cmd,
10142 struct drm_i915_gem_object *obj)
10144 struct intel_framebuffer *intel_fb;
10147 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
10149 drm_gem_object_unreference(&obj->base);
10150 return ERR_PTR(-ENOMEM);
10153 ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
10157 return &intel_fb->base;
10159 drm_gem_object_unreference(&obj->base);
10162 return ERR_PTR(ret);
10165 static struct drm_framebuffer *
10166 intel_framebuffer_create(struct drm_device *dev,
10167 struct drm_mode_fb_cmd2 *mode_cmd,
10168 struct drm_i915_gem_object *obj)
10170 struct drm_framebuffer *fb;
10173 ret = i915_mutex_lock_interruptible(dev);
10175 return ERR_PTR(ret);
10176 fb = __intel_framebuffer_create(dev, mode_cmd, obj);
10177 mutex_unlock(&dev->struct_mutex);
10183 intel_framebuffer_pitch_for_width(int width, int bpp)
10185 u32 pitch = DIV_ROUND_UP(width * bpp, 8);
10186 return ALIGN(pitch, 64);
10190 intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
10192 u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
10193 return PAGE_ALIGN(pitch * mode->vdisplay);
10196 static struct drm_framebuffer *
10197 intel_framebuffer_create_for_mode(struct drm_device *dev,
10198 struct drm_display_mode *mode,
10199 int depth, int bpp)
10201 struct drm_i915_gem_object *obj;
10202 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
10204 obj = i915_gem_alloc_object(dev,
10205 intel_framebuffer_size_for_mode(mode, bpp));
10207 return ERR_PTR(-ENOMEM);
10209 mode_cmd.width = mode->hdisplay;
10210 mode_cmd.height = mode->vdisplay;
10211 mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
10213 mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
10215 return intel_framebuffer_create(dev, &mode_cmd, obj);
10218 static struct drm_framebuffer *
10219 mode_fits_in_fbdev(struct drm_device *dev,
10220 struct drm_display_mode *mode)
10222 #ifdef CONFIG_DRM_I915_FBDEV
10223 struct drm_i915_private *dev_priv = dev->dev_private;
10224 struct drm_i915_gem_object *obj;
10225 struct drm_framebuffer *fb;
10227 if (!dev_priv->fbdev)
10230 if (!dev_priv->fbdev->fb)
10233 obj = dev_priv->fbdev->fb->obj;
10236 fb = &dev_priv->fbdev->fb->base;
10237 if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
10238 fb->bits_per_pixel))
10241 if (obj->base.size < mode->vdisplay * fb->pitches[0])
10250 static int intel_modeset_setup_plane_state(struct drm_atomic_state *state,
10251 struct drm_crtc *crtc,
10252 struct drm_display_mode *mode,
10253 struct drm_framebuffer *fb,
10256 struct drm_plane_state *plane_state;
10257 int hdisplay, vdisplay;
10260 plane_state = drm_atomic_get_plane_state(state, crtc->primary);
10261 if (IS_ERR(plane_state))
10262 return PTR_ERR(plane_state);
10265 drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay);
10267 hdisplay = vdisplay = 0;
10269 ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL);
10272 drm_atomic_set_fb_for_plane(plane_state, fb);
10273 plane_state->crtc_x = 0;
10274 plane_state->crtc_y = 0;
10275 plane_state->crtc_w = hdisplay;
10276 plane_state->crtc_h = vdisplay;
10277 plane_state->src_x = x << 16;
10278 plane_state->src_y = y << 16;
10279 plane_state->src_w = hdisplay << 16;
10280 plane_state->src_h = vdisplay << 16;
10285 bool intel_get_load_detect_pipe(struct drm_connector *connector,
10286 struct drm_display_mode *mode,
10287 struct intel_load_detect_pipe *old,
10288 struct drm_modeset_acquire_ctx *ctx)
10290 struct intel_crtc *intel_crtc;
10291 struct intel_encoder *intel_encoder =
10292 intel_attached_encoder(connector);
10293 struct drm_crtc *possible_crtc;
10294 struct drm_encoder *encoder = &intel_encoder->base;
10295 struct drm_crtc *crtc = NULL;
10296 struct drm_device *dev = encoder->dev;
10297 struct drm_framebuffer *fb;
10298 struct drm_mode_config *config = &dev->mode_config;
10299 struct drm_atomic_state *state = NULL;
10300 struct drm_connector_state *connector_state;
10301 struct intel_crtc_state *crtc_state;
10304 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10305 connector->base.id, connector->name,
10306 encoder->base.id, encoder->name);
10309 ret = drm_modeset_lock(&config->connection_mutex, ctx);
10314 * Algorithm gets a little messy:
10316 * - if the connector already has an assigned crtc, use it (but make
10317 * sure it's on first)
10319 * - try to find the first unused crtc that can drive this connector,
10320 * and use that if we find one
10323 /* See if we already have a CRTC for this connector */
10324 if (encoder->crtc) {
10325 crtc = encoder->crtc;
10327 ret = drm_modeset_lock(&crtc->mutex, ctx);
10330 ret = drm_modeset_lock(&crtc->primary->mutex, ctx);
10334 old->dpms_mode = connector->dpms;
10335 old->load_detect_temp = false;
10337 /* Make sure the crtc and connector are running */
10338 if (connector->dpms != DRM_MODE_DPMS_ON)
10339 connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
10344 /* Find an unused one (if possible) */
10345 for_each_crtc(dev, possible_crtc) {
10347 if (!(encoder->possible_crtcs & (1 << i)))
10349 if (possible_crtc->state->enable)
10352 crtc = possible_crtc;
10357 * If we didn't find an unused CRTC, don't use any.
10360 DRM_DEBUG_KMS("no pipe available for load-detect\n");
10364 ret = drm_modeset_lock(&crtc->mutex, ctx);
10367 ret = drm_modeset_lock(&crtc->primary->mutex, ctx);
10371 intel_crtc = to_intel_crtc(crtc);
10372 old->dpms_mode = connector->dpms;
10373 old->load_detect_temp = true;
10374 old->release_fb = NULL;
10376 state = drm_atomic_state_alloc(dev);
10380 state->acquire_ctx = ctx;
10382 connector_state = drm_atomic_get_connector_state(state, connector);
10383 if (IS_ERR(connector_state)) {
10384 ret = PTR_ERR(connector_state);
10388 connector_state->crtc = crtc;
10389 connector_state->best_encoder = &intel_encoder->base;
10391 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10392 if (IS_ERR(crtc_state)) {
10393 ret = PTR_ERR(crtc_state);
10397 crtc_state->base.active = crtc_state->base.enable = true;
10400 mode = &load_detect_mode;
10402 /* We need a framebuffer large enough to accommodate all accesses
10403 * that the plane may generate whilst we perform load detection.
10404 * We can not rely on the fbcon either being present (we get called
10405 * during its initialisation to detect all boot displays, or it may
10406 * not even exist) or that it is large enough to satisfy the
10409 fb = mode_fits_in_fbdev(dev, mode);
10411 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
10412 fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
10413 old->release_fb = fb;
10415 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
10417 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
10421 ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0);
10425 drm_mode_copy(&crtc_state->base.mode, mode);
10427 if (intel_set_mode(state)) {
10428 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
10429 if (old->release_fb)
10430 old->release_fb->funcs->destroy(old->release_fb);
10433 crtc->primary->crtc = crtc;
10435 /* let the connector get through one full cycle before testing */
10436 intel_wait_for_vblank(dev, intel_crtc->pipe);
10440 drm_atomic_state_free(state);
10443 if (ret == -EDEADLK) {
10444 drm_modeset_backoff(ctx);
10451 void intel_release_load_detect_pipe(struct drm_connector *connector,
10452 struct intel_load_detect_pipe *old,
10453 struct drm_modeset_acquire_ctx *ctx)
10455 struct drm_device *dev = connector->dev;
10456 struct intel_encoder *intel_encoder =
10457 intel_attached_encoder(connector);
10458 struct drm_encoder *encoder = &intel_encoder->base;
10459 struct drm_crtc *crtc = encoder->crtc;
10460 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10461 struct drm_atomic_state *state;
10462 struct drm_connector_state *connector_state;
10463 struct intel_crtc_state *crtc_state;
10466 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10467 connector->base.id, connector->name,
10468 encoder->base.id, encoder->name);
10470 if (old->load_detect_temp) {
10471 state = drm_atomic_state_alloc(dev);
10475 state->acquire_ctx = ctx;
10477 connector_state = drm_atomic_get_connector_state(state, connector);
10478 if (IS_ERR(connector_state))
10481 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10482 if (IS_ERR(crtc_state))
10485 connector_state->best_encoder = NULL;
10486 connector_state->crtc = NULL;
10488 crtc_state->base.enable = crtc_state->base.active = false;
10490 ret = intel_modeset_setup_plane_state(state, crtc, NULL, NULL,
10495 ret = intel_set_mode(state);
10499 if (old->release_fb) {
10500 drm_framebuffer_unregister_private(old->release_fb);
10501 drm_framebuffer_unreference(old->release_fb);
10507 /* Switch crtc and encoder back off if necessary */
10508 if (old->dpms_mode != DRM_MODE_DPMS_ON)
10509 connector->funcs->dpms(connector, old->dpms_mode);
10513 DRM_DEBUG_KMS("Couldn't release load detect pipe.\n");
10514 drm_atomic_state_free(state);
10517 static int i9xx_pll_refclk(struct drm_device *dev,
10518 const struct intel_crtc_state *pipe_config)
10520 struct drm_i915_private *dev_priv = dev->dev_private;
10521 u32 dpll = pipe_config->dpll_hw_state.dpll;
10523 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
10524 return dev_priv->vbt.lvds_ssc_freq;
10525 else if (HAS_PCH_SPLIT(dev))
10527 else if (!IS_GEN2(dev))
10533 /* Returns the clock of the currently programmed mode of the given pipe. */
10534 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
10535 struct intel_crtc_state *pipe_config)
10537 struct drm_device *dev = crtc->base.dev;
10538 struct drm_i915_private *dev_priv = dev->dev_private;
10539 int pipe = pipe_config->cpu_transcoder;
10540 u32 dpll = pipe_config->dpll_hw_state.dpll;
10542 intel_clock_t clock;
10544 int refclk = i9xx_pll_refclk(dev, pipe_config);
10546 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
10547 fp = pipe_config->dpll_hw_state.fp0;
10549 fp = pipe_config->dpll_hw_state.fp1;
10551 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
10552 if (IS_PINEVIEW(dev)) {
10553 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10554 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
10556 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10557 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10560 if (!IS_GEN2(dev)) {
10561 if (IS_PINEVIEW(dev))
10562 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10563 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
10565 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
10566 DPLL_FPA01_P1_POST_DIV_SHIFT);
10568 switch (dpll & DPLL_MODE_MASK) {
10569 case DPLLB_MODE_DAC_SERIAL:
10570 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10573 case DPLLB_MODE_LVDS:
10574 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10578 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10579 "mode\n", (int)(dpll & DPLL_MODE_MASK));
10583 if (IS_PINEVIEW(dev))
10584 port_clock = pnv_calc_dpll_params(refclk, &clock);
10586 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10588 u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS);
10589 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
10592 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10593 DPLL_FPA01_P1_POST_DIV_SHIFT);
10595 if (lvds & LVDS_CLKB_POWER_UP)
10600 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10603 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10604 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10606 if (dpll & PLL_P2_DIVIDE_BY_4)
10612 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10616 * This value includes pixel_multiplier. We will use
10617 * port_clock to compute adjusted_mode.crtc_clock in the
10618 * encoder's get_config() function.
10620 pipe_config->port_clock = port_clock;
10623 int intel_dotclock_calculate(int link_freq,
10624 const struct intel_link_m_n *m_n)
10627 * The calculation for the data clock is:
10628 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10629 * But we want to avoid losing precison if possible, so:
10630 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10632 * and the link clock is simpler:
10633 * link_clock = (m * link_clock) / n
10639 return div_u64((u64)m_n->link_m * link_freq, m_n->link_n);
10642 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
10643 struct intel_crtc_state *pipe_config)
10645 struct drm_device *dev = crtc->base.dev;
10647 /* read out port_clock from the DPLL */
10648 i9xx_crtc_clock_get(crtc, pipe_config);
10651 * This value does not include pixel_multiplier.
10652 * We will check that port_clock and adjusted_mode.crtc_clock
10653 * agree once we know their relationship in the encoder's
10654 * get_config() function.
10656 pipe_config->base.adjusted_mode.crtc_clock =
10657 intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000,
10658 &pipe_config->fdi_m_n);
10661 /** Returns the currently programmed mode of the given pipe. */
10662 struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
10663 struct drm_crtc *crtc)
10665 struct drm_i915_private *dev_priv = dev->dev_private;
10666 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10667 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
10668 struct drm_display_mode *mode;
10669 struct intel_crtc_state pipe_config;
10670 int htot = I915_READ(HTOTAL(cpu_transcoder));
10671 int hsync = I915_READ(HSYNC(cpu_transcoder));
10672 int vtot = I915_READ(VTOTAL(cpu_transcoder));
10673 int vsync = I915_READ(VSYNC(cpu_transcoder));
10674 enum pipe pipe = intel_crtc->pipe;
10676 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10681 * Construct a pipe_config sufficient for getting the clock info
10682 * back out of crtc_clock_get.
10684 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
10685 * to use a real value here instead.
10687 pipe_config.cpu_transcoder = (enum transcoder) pipe;
10688 pipe_config.pixel_multiplier = 1;
10689 pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe));
10690 pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe));
10691 pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe));
10692 i9xx_crtc_clock_get(intel_crtc, &pipe_config);
10694 mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier;
10695 mode->hdisplay = (htot & 0xffff) + 1;
10696 mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
10697 mode->hsync_start = (hsync & 0xffff) + 1;
10698 mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
10699 mode->vdisplay = (vtot & 0xffff) + 1;
10700 mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
10701 mode->vsync_start = (vsync & 0xffff) + 1;
10702 mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
10704 drm_mode_set_name(mode);
10709 void intel_mark_busy(struct drm_device *dev)
10711 struct drm_i915_private *dev_priv = dev->dev_private;
10713 if (dev_priv->mm.busy)
10716 intel_runtime_pm_get(dev_priv);
10717 i915_update_gfx_val(dev_priv);
10718 if (INTEL_INFO(dev)->gen >= 6)
10719 gen6_rps_busy(dev_priv);
10720 dev_priv->mm.busy = true;
10723 void intel_mark_idle(struct drm_device *dev)
10725 struct drm_i915_private *dev_priv = dev->dev_private;
10727 if (!dev_priv->mm.busy)
10730 dev_priv->mm.busy = false;
10732 if (INTEL_INFO(dev)->gen >= 6)
10733 gen6_rps_idle(dev->dev_private);
10735 intel_runtime_pm_put(dev_priv);
10738 static void intel_crtc_destroy(struct drm_crtc *crtc)
10740 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10741 struct drm_device *dev = crtc->dev;
10742 struct intel_unpin_work *work;
10744 spin_lock_irq(&dev->event_lock);
10745 work = intel_crtc->unpin_work;
10746 intel_crtc->unpin_work = NULL;
10747 spin_unlock_irq(&dev->event_lock);
10750 cancel_work_sync(&work->work);
10754 drm_crtc_cleanup(crtc);
10759 static void intel_unpin_work_fn(struct work_struct *__work)
10761 struct intel_unpin_work *work =
10762 container_of(__work, struct intel_unpin_work, work);
10763 struct intel_crtc *crtc = to_intel_crtc(work->crtc);
10764 struct drm_device *dev = crtc->base.dev;
10765 struct drm_i915_private *dev_priv = dev->dev_private;
10766 struct drm_plane *primary = crtc->base.primary;
10768 mutex_lock(&dev->struct_mutex);
10769 intel_unpin_fb_obj(work->old_fb, primary->state);
10770 drm_gem_object_unreference(&work->pending_flip_obj->base);
10772 intel_fbc_update(dev_priv);
10774 if (work->flip_queued_req)
10775 i915_gem_request_assign(&work->flip_queued_req, NULL);
10776 mutex_unlock(&dev->struct_mutex);
10778 intel_frontbuffer_flip_complete(dev, to_intel_plane(primary)->frontbuffer_bit);
10779 drm_framebuffer_unreference(work->old_fb);
10781 BUG_ON(atomic_read(&crtc->unpin_work_count) == 0);
10782 atomic_dec(&crtc->unpin_work_count);
10787 static void do_intel_finish_page_flip(struct drm_device *dev,
10788 struct drm_crtc *crtc)
10790 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10791 struct intel_unpin_work *work;
10792 unsigned long flags;
10794 /* Ignore early vblank irqs */
10795 if (intel_crtc == NULL)
10799 * This is called both by irq handlers and the reset code (to complete
10800 * lost pageflips) so needs the full irqsave spinlocks.
10802 spin_lock_irqsave(&dev->event_lock, flags);
10803 work = intel_crtc->unpin_work;
10805 /* Ensure we don't miss a work->pending update ... */
10808 if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
10809 spin_unlock_irqrestore(&dev->event_lock, flags);
10813 page_flip_completed(intel_crtc);
10815 spin_unlock_irqrestore(&dev->event_lock, flags);
10818 void intel_finish_page_flip(struct drm_device *dev, int pipe)
10820 struct drm_i915_private *dev_priv = dev->dev_private;
10821 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
10823 do_intel_finish_page_flip(dev, crtc);
10826 void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
10828 struct drm_i915_private *dev_priv = dev->dev_private;
10829 struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
10831 do_intel_finish_page_flip(dev, crtc);
10834 /* Is 'a' after or equal to 'b'? */
10835 static bool g4x_flip_count_after_eq(u32 a, u32 b)
10837 return !((a - b) & 0x80000000);
10840 static bool page_flip_finished(struct intel_crtc *crtc)
10842 struct drm_device *dev = crtc->base.dev;
10843 struct drm_i915_private *dev_priv = dev->dev_private;
10845 if (i915_reset_in_progress(&dev_priv->gpu_error) ||
10846 crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
10850 * The relevant registers doen't exist on pre-ctg.
10851 * As the flip done interrupt doesn't trigger for mmio
10852 * flips on gmch platforms, a flip count check isn't
10853 * really needed there. But since ctg has the registers,
10854 * include it in the check anyway.
10856 if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev))
10860 * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
10861 * used the same base address. In that case the mmio flip might
10862 * have completed, but the CS hasn't even executed the flip yet.
10864 * A flip count check isn't enough as the CS might have updated
10865 * the base address just after start of vblank, but before we
10866 * managed to process the interrupt. This means we'd complete the
10867 * CS flip too soon.
10869 * Combining both checks should get us a good enough result. It may
10870 * still happen that the CS flip has been executed, but has not
10871 * yet actually completed. But in case the base address is the same
10872 * anyway, we don't really care.
10874 return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) ==
10875 crtc->unpin_work->gtt_offset &&
10876 g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)),
10877 crtc->unpin_work->flip_count);
10880 void intel_prepare_page_flip(struct drm_device *dev, int plane)
10882 struct drm_i915_private *dev_priv = dev->dev_private;
10883 struct intel_crtc *intel_crtc =
10884 to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
10885 unsigned long flags;
10889 * This is called both by irq handlers and the reset code (to complete
10890 * lost pageflips) so needs the full irqsave spinlocks.
10892 * NB: An MMIO update of the plane base pointer will also
10893 * generate a page-flip completion irq, i.e. every modeset
10894 * is also accompanied by a spurious intel_prepare_page_flip().
10896 spin_lock_irqsave(&dev->event_lock, flags);
10897 if (intel_crtc->unpin_work && page_flip_finished(intel_crtc))
10898 atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
10899 spin_unlock_irqrestore(&dev->event_lock, flags);
10902 static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
10904 /* Ensure that the work item is consistent when activating it ... */
10906 atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
10907 /* and that it is marked active as soon as the irq could fire. */
10911 static int intel_gen2_queue_flip(struct drm_device *dev,
10912 struct drm_crtc *crtc,
10913 struct drm_framebuffer *fb,
10914 struct drm_i915_gem_object *obj,
10915 struct drm_i915_gem_request *req,
10918 struct intel_engine_cs *ring = req->ring;
10919 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10923 ret = intel_ring_begin(req, 6);
10927 /* Can't queue multiple flips, so wait for the previous
10928 * one to finish before executing the next.
10930 if (intel_crtc->plane)
10931 flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
10933 flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
10934 intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
10935 intel_ring_emit(ring, MI_NOOP);
10936 intel_ring_emit(ring, MI_DISPLAY_FLIP |
10937 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
10938 intel_ring_emit(ring, fb->pitches[0]);
10939 intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
10940 intel_ring_emit(ring, 0); /* aux display base address, unused */
10942 intel_mark_page_flip_active(intel_crtc);
10946 static int intel_gen3_queue_flip(struct drm_device *dev,
10947 struct drm_crtc *crtc,
10948 struct drm_framebuffer *fb,
10949 struct drm_i915_gem_object *obj,
10950 struct drm_i915_gem_request *req,
10953 struct intel_engine_cs *ring = req->ring;
10954 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10958 ret = intel_ring_begin(req, 6);
10962 if (intel_crtc->plane)
10963 flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
10965 flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
10966 intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
10967 intel_ring_emit(ring, MI_NOOP);
10968 intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
10969 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
10970 intel_ring_emit(ring, fb->pitches[0]);
10971 intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
10972 intel_ring_emit(ring, MI_NOOP);
10974 intel_mark_page_flip_active(intel_crtc);
10978 static int intel_gen4_queue_flip(struct drm_device *dev,
10979 struct drm_crtc *crtc,
10980 struct drm_framebuffer *fb,
10981 struct drm_i915_gem_object *obj,
10982 struct drm_i915_gem_request *req,
10985 struct intel_engine_cs *ring = req->ring;
10986 struct drm_i915_private *dev_priv = dev->dev_private;
10987 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10988 uint32_t pf, pipesrc;
10991 ret = intel_ring_begin(req, 4);
10995 /* i965+ uses the linear or tiled offsets from the
10996 * Display Registers (which do not change across a page-flip)
10997 * so we need only reprogram the base address.
10999 intel_ring_emit(ring, MI_DISPLAY_FLIP |
11000 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
11001 intel_ring_emit(ring, fb->pitches[0]);
11002 intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset |
11005 /* XXX Enabling the panel-fitter across page-flip is so far
11006 * untested on non-native modes, so ignore it for now.
11007 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
11010 pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
11011 intel_ring_emit(ring, pf | pipesrc);
11013 intel_mark_page_flip_active(intel_crtc);
11017 static int intel_gen6_queue_flip(struct drm_device *dev,
11018 struct drm_crtc *crtc,
11019 struct drm_framebuffer *fb,
11020 struct drm_i915_gem_object *obj,
11021 struct drm_i915_gem_request *req,
11024 struct intel_engine_cs *ring = req->ring;
11025 struct drm_i915_private *dev_priv = dev->dev_private;
11026 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11027 uint32_t pf, pipesrc;
11030 ret = intel_ring_begin(req, 4);
11034 intel_ring_emit(ring, MI_DISPLAY_FLIP |
11035 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
11036 intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
11037 intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
11039 /* Contrary to the suggestions in the documentation,
11040 * "Enable Panel Fitter" does not seem to be required when page
11041 * flipping with a non-native mode, and worse causes a normal
11043 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
11046 pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
11047 intel_ring_emit(ring, pf | pipesrc);
11049 intel_mark_page_flip_active(intel_crtc);
11053 static int intel_gen7_queue_flip(struct drm_device *dev,
11054 struct drm_crtc *crtc,
11055 struct drm_framebuffer *fb,
11056 struct drm_i915_gem_object *obj,
11057 struct drm_i915_gem_request *req,
11060 struct intel_engine_cs *ring = req->ring;
11061 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11062 uint32_t plane_bit = 0;
11065 switch (intel_crtc->plane) {
11067 plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
11070 plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
11073 plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
11076 WARN_ONCE(1, "unknown plane in flip command\n");
11081 if (ring->id == RCS) {
11084 * On Gen 8, SRM is now taking an extra dword to accommodate
11085 * 48bits addresses, and we need a NOOP for the batch size to
11093 * BSpec MI_DISPLAY_FLIP for IVB:
11094 * "The full packet must be contained within the same cache line."
11096 * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
11097 * cacheline, if we ever start emitting more commands before
11098 * the MI_DISPLAY_FLIP we may need to first emit everything else,
11099 * then do the cacheline alignment, and finally emit the
11102 ret = intel_ring_cacheline_align(req);
11106 ret = intel_ring_begin(req, len);
11110 /* Unmask the flip-done completion message. Note that the bspec says that
11111 * we should do this for both the BCS and RCS, and that we must not unmask
11112 * more than one flip event at any time (or ensure that one flip message
11113 * can be sent by waiting for flip-done prior to queueing new flips).
11114 * Experimentation says that BCS works despite DERRMR masking all
11115 * flip-done completion events and that unmasking all planes at once
11116 * for the RCS also doesn't appear to drop events. Setting the DERRMR
11117 * to zero does lead to lockups within MI_DISPLAY_FLIP.
11119 if (ring->id == RCS) {
11120 intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
11121 intel_ring_emit(ring, DERRMR);
11122 intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE |
11123 DERRMR_PIPEB_PRI_FLIP_DONE |
11124 DERRMR_PIPEC_PRI_FLIP_DONE));
11126 intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) |
11127 MI_SRM_LRM_GLOBAL_GTT);
11129 intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) |
11130 MI_SRM_LRM_GLOBAL_GTT);
11131 intel_ring_emit(ring, DERRMR);
11132 intel_ring_emit(ring, ring->scratch.gtt_offset + 256);
11133 if (IS_GEN8(dev)) {
11134 intel_ring_emit(ring, 0);
11135 intel_ring_emit(ring, MI_NOOP);
11139 intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
11140 intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
11141 intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
11142 intel_ring_emit(ring, (MI_NOOP));
11144 intel_mark_page_flip_active(intel_crtc);
11148 static bool use_mmio_flip(struct intel_engine_cs *ring,
11149 struct drm_i915_gem_object *obj)
11152 * This is not being used for older platforms, because
11153 * non-availability of flip done interrupt forces us to use
11154 * CS flips. Older platforms derive flip done using some clever
11155 * tricks involving the flip_pending status bits and vblank irqs.
11156 * So using MMIO flips there would disrupt this mechanism.
11162 if (INTEL_INFO(ring->dev)->gen < 5)
11165 if (i915.use_mmio_flip < 0)
11167 else if (i915.use_mmio_flip > 0)
11169 else if (i915.enable_execlists)
11172 return ring != i915_gem_request_get_ring(obj->last_write_req);
11175 static void skl_do_mmio_flip(struct intel_crtc *intel_crtc)
11177 struct drm_device *dev = intel_crtc->base.dev;
11178 struct drm_i915_private *dev_priv = dev->dev_private;
11179 struct drm_framebuffer *fb = intel_crtc->base.primary->fb;
11180 const enum pipe pipe = intel_crtc->pipe;
11183 ctl = I915_READ(PLANE_CTL(pipe, 0));
11184 ctl &= ~PLANE_CTL_TILED_MASK;
11185 switch (fb->modifier[0]) {
11186 case DRM_FORMAT_MOD_NONE:
11188 case I915_FORMAT_MOD_X_TILED:
11189 ctl |= PLANE_CTL_TILED_X;
11191 case I915_FORMAT_MOD_Y_TILED:
11192 ctl |= PLANE_CTL_TILED_Y;
11194 case I915_FORMAT_MOD_Yf_TILED:
11195 ctl |= PLANE_CTL_TILED_YF;
11198 MISSING_CASE(fb->modifier[0]);
11202 * The stride is either expressed as a multiple of 64 bytes chunks for
11203 * linear buffers or in number of tiles for tiled buffers.
11205 stride = fb->pitches[0] /
11206 intel_fb_stride_alignment(dev, fb->modifier[0],
11210 * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on
11211 * PLANE_SURF updates, the update is then guaranteed to be atomic.
11213 I915_WRITE(PLANE_CTL(pipe, 0), ctl);
11214 I915_WRITE(PLANE_STRIDE(pipe, 0), stride);
11216 I915_WRITE(PLANE_SURF(pipe, 0), intel_crtc->unpin_work->gtt_offset);
11217 POSTING_READ(PLANE_SURF(pipe, 0));
11220 static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc)
11222 struct drm_device *dev = intel_crtc->base.dev;
11223 struct drm_i915_private *dev_priv = dev->dev_private;
11224 struct intel_framebuffer *intel_fb =
11225 to_intel_framebuffer(intel_crtc->base.primary->fb);
11226 struct drm_i915_gem_object *obj = intel_fb->obj;
11230 reg = DSPCNTR(intel_crtc->plane);
11231 dspcntr = I915_READ(reg);
11233 if (obj->tiling_mode != I915_TILING_NONE)
11234 dspcntr |= DISPPLANE_TILED;
11236 dspcntr &= ~DISPPLANE_TILED;
11238 I915_WRITE(reg, dspcntr);
11240 I915_WRITE(DSPSURF(intel_crtc->plane),
11241 intel_crtc->unpin_work->gtt_offset);
11242 POSTING_READ(DSPSURF(intel_crtc->plane));
11247 * XXX: This is the temporary way to update the plane registers until we get
11248 * around to using the usual plane update functions for MMIO flips
11250 static void intel_do_mmio_flip(struct intel_crtc *intel_crtc)
11252 struct drm_device *dev = intel_crtc->base.dev;
11253 bool atomic_update;
11254 u32 start_vbl_count;
11256 intel_mark_page_flip_active(intel_crtc);
11258 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
11260 if (INTEL_INFO(dev)->gen >= 9)
11261 skl_do_mmio_flip(intel_crtc);
11263 /* use_mmio_flip() retricts MMIO flips to ilk+ */
11264 ilk_do_mmio_flip(intel_crtc);
11267 intel_pipe_update_end(intel_crtc, start_vbl_count);
11270 static void intel_mmio_flip_work_func(struct work_struct *work)
11272 struct intel_mmio_flip *mmio_flip =
11273 container_of(work, struct intel_mmio_flip, work);
11275 if (mmio_flip->req)
11276 WARN_ON(__i915_wait_request(mmio_flip->req,
11277 mmio_flip->crtc->reset_counter,
11279 &mmio_flip->i915->rps.mmioflips));
11281 intel_do_mmio_flip(mmio_flip->crtc);
11283 i915_gem_request_unreference__unlocked(mmio_flip->req);
11287 static int intel_queue_mmio_flip(struct drm_device *dev,
11288 struct drm_crtc *crtc,
11289 struct drm_framebuffer *fb,
11290 struct drm_i915_gem_object *obj,
11291 struct intel_engine_cs *ring,
11294 struct intel_mmio_flip *mmio_flip;
11296 mmio_flip = kmalloc(sizeof(*mmio_flip), GFP_KERNEL);
11297 if (mmio_flip == NULL)
11300 mmio_flip->i915 = to_i915(dev);
11301 mmio_flip->req = i915_gem_request_reference(obj->last_write_req);
11302 mmio_flip->crtc = to_intel_crtc(crtc);
11304 INIT_WORK(&mmio_flip->work, intel_mmio_flip_work_func);
11305 schedule_work(&mmio_flip->work);
11310 static int intel_default_queue_flip(struct drm_device *dev,
11311 struct drm_crtc *crtc,
11312 struct drm_framebuffer *fb,
11313 struct drm_i915_gem_object *obj,
11314 struct drm_i915_gem_request *req,
11320 static bool __intel_pageflip_stall_check(struct drm_device *dev,
11321 struct drm_crtc *crtc)
11323 struct drm_i915_private *dev_priv = dev->dev_private;
11324 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11325 struct intel_unpin_work *work = intel_crtc->unpin_work;
11328 if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE)
11331 if (!work->enable_stall_check)
11334 if (work->flip_ready_vblank == 0) {
11335 if (work->flip_queued_req &&
11336 !i915_gem_request_completed(work->flip_queued_req, true))
11339 work->flip_ready_vblank = drm_crtc_vblank_count(crtc);
11342 if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3)
11345 /* Potential stall - if we see that the flip has happened,
11346 * assume a missed interrupt. */
11347 if (INTEL_INFO(dev)->gen >= 4)
11348 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane)));
11350 addr = I915_READ(DSPADDR(intel_crtc->plane));
11352 /* There is a potential issue here with a false positive after a flip
11353 * to the same address. We could address this by checking for a
11354 * non-incrementing frame counter.
11356 return addr == work->gtt_offset;
11359 void intel_check_page_flip(struct drm_device *dev, int pipe)
11361 struct drm_i915_private *dev_priv = dev->dev_private;
11362 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
11363 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11364 struct intel_unpin_work *work;
11366 WARN_ON(!in_interrupt());
11371 spin_lock(&dev->event_lock);
11372 work = intel_crtc->unpin_work;
11373 if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) {
11374 WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n",
11375 work->flip_queued_vblank, drm_vblank_count(dev, pipe));
11376 page_flip_completed(intel_crtc);
11379 if (work != NULL &&
11380 drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1)
11381 intel_queue_rps_boost_for_request(dev, work->flip_queued_req);
11382 spin_unlock(&dev->event_lock);
11385 static int intel_crtc_page_flip(struct drm_crtc *crtc,
11386 struct drm_framebuffer *fb,
11387 struct drm_pending_vblank_event *event,
11388 uint32_t page_flip_flags)
11390 struct drm_device *dev = crtc->dev;
11391 struct drm_i915_private *dev_priv = dev->dev_private;
11392 struct drm_framebuffer *old_fb = crtc->primary->fb;
11393 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
11394 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11395 struct drm_plane *primary = crtc->primary;
11396 enum pipe pipe = intel_crtc->pipe;
11397 struct intel_unpin_work *work;
11398 struct intel_engine_cs *ring;
11400 struct drm_i915_gem_request *request = NULL;
11404 * drm_mode_page_flip_ioctl() should already catch this, but double
11405 * check to be safe. In the future we may enable pageflipping from
11406 * a disabled primary plane.
11408 if (WARN_ON(intel_fb_obj(old_fb) == NULL))
11411 /* Can't change pixel format via MI display flips. */
11412 if (fb->pixel_format != crtc->primary->fb->pixel_format)
11416 * TILEOFF/LINOFF registers can't be changed via MI display flips.
11417 * Note that pitch changes could also affect these register.
11419 if (INTEL_INFO(dev)->gen > 3 &&
11420 (fb->offsets[0] != crtc->primary->fb->offsets[0] ||
11421 fb->pitches[0] != crtc->primary->fb->pitches[0]))
11424 if (i915_terminally_wedged(&dev_priv->gpu_error))
11427 work = kzalloc(sizeof(*work), GFP_KERNEL);
11431 work->event = event;
11433 work->old_fb = old_fb;
11434 INIT_WORK(&work->work, intel_unpin_work_fn);
11436 ret = drm_crtc_vblank_get(crtc);
11440 /* We borrow the event spin lock for protecting unpin_work */
11441 spin_lock_irq(&dev->event_lock);
11442 if (intel_crtc->unpin_work) {
11443 /* Before declaring the flip queue wedged, check if
11444 * the hardware completed the operation behind our backs.
11446 if (__intel_pageflip_stall_check(dev, crtc)) {
11447 DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
11448 page_flip_completed(intel_crtc);
11450 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
11451 spin_unlock_irq(&dev->event_lock);
11453 drm_crtc_vblank_put(crtc);
11458 intel_crtc->unpin_work = work;
11459 spin_unlock_irq(&dev->event_lock);
11461 if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
11462 flush_workqueue(dev_priv->wq);
11464 /* Reference the objects for the scheduled work. */
11465 drm_framebuffer_reference(work->old_fb);
11466 drm_gem_object_reference(&obj->base);
11468 crtc->primary->fb = fb;
11469 update_state_fb(crtc->primary);
11471 work->pending_flip_obj = obj;
11473 ret = i915_mutex_lock_interruptible(dev);
11477 atomic_inc(&intel_crtc->unpin_work_count);
11478 intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
11480 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
11481 work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1;
11483 if (IS_VALLEYVIEW(dev)) {
11484 ring = &dev_priv->ring[BCS];
11485 if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode)
11486 /* vlv: DISPLAY_FLIP fails to change tiling */
11488 } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) {
11489 ring = &dev_priv->ring[BCS];
11490 } else if (INTEL_INFO(dev)->gen >= 7) {
11491 ring = i915_gem_request_get_ring(obj->last_write_req);
11492 if (ring == NULL || ring->id != RCS)
11493 ring = &dev_priv->ring[BCS];
11495 ring = &dev_priv->ring[RCS];
11498 mmio_flip = use_mmio_flip(ring, obj);
11500 /* When using CS flips, we want to emit semaphores between rings.
11501 * However, when using mmio flips we will create a task to do the
11502 * synchronisation, so all we want here is to pin the framebuffer
11503 * into the display plane and skip any waits.
11505 ret = intel_pin_and_fence_fb_obj(crtc->primary, fb,
11506 crtc->primary->state,
11507 mmio_flip ? i915_gem_request_get_ring(obj->last_write_req) : ring, &request);
11509 goto cleanup_pending;
11511 work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), obj)
11512 + intel_crtc->dspaddr_offset;
11515 ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring,
11518 goto cleanup_unpin;
11520 i915_gem_request_assign(&work->flip_queued_req,
11521 obj->last_write_req);
11524 ret = i915_gem_request_alloc(ring, ring->default_context, &request);
11526 goto cleanup_unpin;
11529 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, request,
11532 goto cleanup_unpin;
11534 i915_gem_request_assign(&work->flip_queued_req, request);
11538 i915_add_request_no_flush(request);
11540 work->flip_queued_vblank = drm_crtc_vblank_count(crtc);
11541 work->enable_stall_check = true;
11543 i915_gem_track_fb(intel_fb_obj(work->old_fb), obj,
11544 to_intel_plane(primary)->frontbuffer_bit);
11545 mutex_unlock(&dev->struct_mutex);
11547 intel_fbc_disable(dev_priv);
11548 intel_frontbuffer_flip_prepare(dev,
11549 to_intel_plane(primary)->frontbuffer_bit);
11551 trace_i915_flip_request(intel_crtc->plane, obj);
11556 intel_unpin_fb_obj(fb, crtc->primary->state);
11559 i915_gem_request_cancel(request);
11560 atomic_dec(&intel_crtc->unpin_work_count);
11561 mutex_unlock(&dev->struct_mutex);
11563 crtc->primary->fb = old_fb;
11564 update_state_fb(crtc->primary);
11566 drm_gem_object_unreference_unlocked(&obj->base);
11567 drm_framebuffer_unreference(work->old_fb);
11569 spin_lock_irq(&dev->event_lock);
11570 intel_crtc->unpin_work = NULL;
11571 spin_unlock_irq(&dev->event_lock);
11573 drm_crtc_vblank_put(crtc);
11578 struct drm_atomic_state *state;
11579 struct drm_plane_state *plane_state;
11582 state = drm_atomic_state_alloc(dev);
11585 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
11588 plane_state = drm_atomic_get_plane_state(state, primary);
11589 ret = PTR_ERR_OR_ZERO(plane_state);
11591 drm_atomic_set_fb_for_plane(plane_state, fb);
11593 ret = drm_atomic_set_crtc_for_plane(plane_state, crtc);
11595 ret = drm_atomic_commit(state);
11598 if (ret == -EDEADLK) {
11599 drm_modeset_backoff(state->acquire_ctx);
11600 drm_atomic_state_clear(state);
11605 drm_atomic_state_free(state);
11607 if (ret == 0 && event) {
11608 spin_lock_irq(&dev->event_lock);
11609 drm_send_vblank_event(dev, pipe, event);
11610 spin_unlock_irq(&dev->event_lock);
11618 * intel_wm_need_update - Check whether watermarks need updating
11619 * @plane: drm plane
11620 * @state: new plane state
11622 * Check current plane state versus the new one to determine whether
11623 * watermarks need to be recalculated.
11625 * Returns true or false.
11627 static bool intel_wm_need_update(struct drm_plane *plane,
11628 struct drm_plane_state *state)
11630 /* Update watermarks on tiling changes. */
11631 if (!plane->state->fb || !state->fb ||
11632 plane->state->fb->modifier[0] != state->fb->modifier[0] ||
11633 plane->state->rotation != state->rotation)
11636 if (plane->state->crtc_w != state->crtc_w)
11642 int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state,
11643 struct drm_plane_state *plane_state)
11645 struct drm_crtc *crtc = crtc_state->crtc;
11646 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11647 struct drm_plane *plane = plane_state->plane;
11648 struct drm_device *dev = crtc->dev;
11649 struct drm_i915_private *dev_priv = dev->dev_private;
11650 struct intel_plane_state *old_plane_state =
11651 to_intel_plane_state(plane->state);
11652 int idx = intel_crtc->base.base.id, ret;
11653 int i = drm_plane_index(plane);
11654 bool mode_changed = needs_modeset(crtc_state);
11655 bool was_crtc_enabled = crtc->state->active;
11656 bool is_crtc_enabled = crtc_state->active;
11658 bool turn_off, turn_on, visible, was_visible;
11659 struct drm_framebuffer *fb = plane_state->fb;
11661 if (crtc_state && INTEL_INFO(dev)->gen >= 9 &&
11662 plane->type != DRM_PLANE_TYPE_CURSOR) {
11663 ret = skl_update_scaler_plane(
11664 to_intel_crtc_state(crtc_state),
11665 to_intel_plane_state(plane_state));
11671 * Disabling a plane is always okay; we just need to update
11672 * fb tracking in a special way since cleanup_fb() won't
11673 * get called by the plane helpers.
11675 if (old_plane_state->base.fb && !fb)
11676 intel_crtc->atomic.disabled_planes |= 1 << i;
11678 was_visible = old_plane_state->visible;
11679 visible = to_intel_plane_state(plane_state)->visible;
11681 if (!was_crtc_enabled && WARN_ON(was_visible))
11682 was_visible = false;
11684 if (!is_crtc_enabled && WARN_ON(visible))
11687 if (!was_visible && !visible)
11690 turn_off = was_visible && (!visible || mode_changed);
11691 turn_on = visible && (!was_visible || mode_changed);
11693 DRM_DEBUG_ATOMIC("[CRTC:%i] has [PLANE:%i] with fb %i\n", idx,
11694 plane->base.id, fb ? fb->base.id : -1);
11696 DRM_DEBUG_ATOMIC("[PLANE:%i] visible %i -> %i, off %i, on %i, ms %i\n",
11697 plane->base.id, was_visible, visible,
11698 turn_off, turn_on, mode_changed);
11701 intel_crtc->atomic.update_wm_pre = true;
11702 /* must disable cxsr around plane enable/disable */
11703 if (plane->type != DRM_PLANE_TYPE_CURSOR) {
11704 intel_crtc->atomic.disable_cxsr = true;
11705 /* to potentially re-enable cxsr */
11706 intel_crtc->atomic.wait_vblank = true;
11707 intel_crtc->atomic.update_wm_post = true;
11709 } else if (turn_off) {
11710 intel_crtc->atomic.update_wm_post = true;
11711 /* must disable cxsr around plane enable/disable */
11712 if (plane->type != DRM_PLANE_TYPE_CURSOR) {
11713 if (is_crtc_enabled)
11714 intel_crtc->atomic.wait_vblank = true;
11715 intel_crtc->atomic.disable_cxsr = true;
11717 } else if (intel_wm_need_update(plane, plane_state)) {
11718 intel_crtc->atomic.update_wm_pre = true;
11722 intel_crtc->atomic.fb_bits |=
11723 to_intel_plane(plane)->frontbuffer_bit;
11725 switch (plane->type) {
11726 case DRM_PLANE_TYPE_PRIMARY:
11727 intel_crtc->atomic.wait_for_flips = true;
11728 intel_crtc->atomic.pre_disable_primary = turn_off;
11729 intel_crtc->atomic.post_enable_primary = turn_on;
11733 * FIXME: Actually if we will still have any other
11734 * plane enabled on the pipe we could let IPS enabled
11735 * still, but for now lets consider that when we make
11736 * primary invisible by setting DSPCNTR to 0 on
11737 * update_primary_plane function IPS needs to be
11740 intel_crtc->atomic.disable_ips = true;
11742 intel_crtc->atomic.disable_fbc = true;
11746 * FBC does not work on some platforms for rotated
11747 * planes, so disable it when rotation is not 0 and
11748 * update it when rotation is set back to 0.
11750 * FIXME: This is redundant with the fbc update done in
11751 * the primary plane enable function except that that
11752 * one is done too late. We eventually need to unify
11757 INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) &&
11758 dev_priv->fbc.crtc == intel_crtc &&
11759 plane_state->rotation != BIT(DRM_ROTATE_0))
11760 intel_crtc->atomic.disable_fbc = true;
11763 * BDW signals flip done immediately if the plane
11764 * is disabled, even if the plane enable is already
11765 * armed to occur at the next vblank :(
11767 if (turn_on && IS_BROADWELL(dev))
11768 intel_crtc->atomic.wait_vblank = true;
11770 intel_crtc->atomic.update_fbc |= visible || mode_changed;
11772 case DRM_PLANE_TYPE_CURSOR:
11774 case DRM_PLANE_TYPE_OVERLAY:
11775 if (turn_off && !mode_changed) {
11776 intel_crtc->atomic.wait_vblank = true;
11777 intel_crtc->atomic.update_sprite_watermarks |=
11784 static bool encoders_cloneable(const struct intel_encoder *a,
11785 const struct intel_encoder *b)
11787 /* masks could be asymmetric, so check both ways */
11788 return a == b || (a->cloneable & (1 << b->type) &&
11789 b->cloneable & (1 << a->type));
11792 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
11793 struct intel_crtc *crtc,
11794 struct intel_encoder *encoder)
11796 struct intel_encoder *source_encoder;
11797 struct drm_connector *connector;
11798 struct drm_connector_state *connector_state;
11801 for_each_connector_in_state(state, connector, connector_state, i) {
11802 if (connector_state->crtc != &crtc->base)
11806 to_intel_encoder(connector_state->best_encoder);
11807 if (!encoders_cloneable(encoder, source_encoder))
11814 static bool check_encoder_cloning(struct drm_atomic_state *state,
11815 struct intel_crtc *crtc)
11817 struct intel_encoder *encoder;
11818 struct drm_connector *connector;
11819 struct drm_connector_state *connector_state;
11822 for_each_connector_in_state(state, connector, connector_state, i) {
11823 if (connector_state->crtc != &crtc->base)
11826 encoder = to_intel_encoder(connector_state->best_encoder);
11827 if (!check_single_encoder_cloning(state, crtc, encoder))
11834 static int intel_crtc_atomic_check(struct drm_crtc *crtc,
11835 struct drm_crtc_state *crtc_state)
11837 struct drm_device *dev = crtc->dev;
11838 struct drm_i915_private *dev_priv = dev->dev_private;
11839 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11840 struct intel_crtc_state *pipe_config =
11841 to_intel_crtc_state(crtc_state);
11842 struct drm_atomic_state *state = crtc_state->state;
11843 int ret, idx = crtc->base.id;
11844 bool mode_changed = needs_modeset(crtc_state);
11846 if (mode_changed && !check_encoder_cloning(state, intel_crtc)) {
11847 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
11851 I915_STATE_WARN(crtc->state->active != intel_crtc->active,
11852 "[CRTC:%i] mismatch between state->active(%i) and crtc->active(%i)\n",
11853 idx, crtc->state->active, intel_crtc->active);
11855 if (mode_changed && !crtc_state->active)
11856 intel_crtc->atomic.update_wm_post = true;
11858 if (mode_changed && crtc_state->enable &&
11859 dev_priv->display.crtc_compute_clock &&
11860 !WARN_ON(pipe_config->shared_dpll != DPLL_ID_PRIVATE)) {
11861 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
11868 if (INTEL_INFO(dev)->gen >= 9) {
11870 ret = skl_update_scaler_crtc(pipe_config);
11873 ret = intel_atomic_setup_scalers(dev, intel_crtc,
11880 static const struct drm_crtc_helper_funcs intel_helper_funcs = {
11881 .mode_set_base_atomic = intel_pipe_set_base_atomic,
11882 .load_lut = intel_crtc_load_lut,
11883 .atomic_begin = intel_begin_crtc_commit,
11884 .atomic_flush = intel_finish_crtc_commit,
11885 .atomic_check = intel_crtc_atomic_check,
11888 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
11890 struct intel_connector *connector;
11892 for_each_intel_connector(dev, connector) {
11893 if (connector->base.encoder) {
11894 connector->base.state->best_encoder =
11895 connector->base.encoder;
11896 connector->base.state->crtc =
11897 connector->base.encoder->crtc;
11899 connector->base.state->best_encoder = NULL;
11900 connector->base.state->crtc = NULL;
11906 connected_sink_compute_bpp(struct intel_connector *connector,
11907 struct intel_crtc_state *pipe_config)
11909 int bpp = pipe_config->pipe_bpp;
11911 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
11912 connector->base.base.id,
11913 connector->base.name);
11915 /* Don't use an invalid EDID bpc value */
11916 if (connector->base.display_info.bpc &&
11917 connector->base.display_info.bpc * 3 < bpp) {
11918 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
11919 bpp, connector->base.display_info.bpc*3);
11920 pipe_config->pipe_bpp = connector->base.display_info.bpc*3;
11923 /* Clamp bpp to 8 on screens without EDID 1.4 */
11924 if (connector->base.display_info.bpc == 0 && bpp > 24) {
11925 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
11927 pipe_config->pipe_bpp = 24;
11932 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
11933 struct intel_crtc_state *pipe_config)
11935 struct drm_device *dev = crtc->base.dev;
11936 struct drm_atomic_state *state;
11937 struct drm_connector *connector;
11938 struct drm_connector_state *connector_state;
11941 if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)))
11943 else if (INTEL_INFO(dev)->gen >= 5)
11949 pipe_config->pipe_bpp = bpp;
11951 state = pipe_config->base.state;
11953 /* Clamp display bpp to EDID value */
11954 for_each_connector_in_state(state, connector, connector_state, i) {
11955 if (connector_state->crtc != &crtc->base)
11958 connected_sink_compute_bpp(to_intel_connector(connector),
11965 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
11967 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11968 "type: 0x%x flags: 0x%x\n",
11970 mode->crtc_hdisplay, mode->crtc_hsync_start,
11971 mode->crtc_hsync_end, mode->crtc_htotal,
11972 mode->crtc_vdisplay, mode->crtc_vsync_start,
11973 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
11976 static void intel_dump_pipe_config(struct intel_crtc *crtc,
11977 struct intel_crtc_state *pipe_config,
11978 const char *context)
11980 struct drm_device *dev = crtc->base.dev;
11981 struct drm_plane *plane;
11982 struct intel_plane *intel_plane;
11983 struct intel_plane_state *state;
11984 struct drm_framebuffer *fb;
11986 DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id,
11987 context, pipe_config, pipe_name(crtc->pipe));
11989 DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder));
11990 DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
11991 pipe_config->pipe_bpp, pipe_config->dither);
11992 DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11993 pipe_config->has_pch_encoder,
11994 pipe_config->fdi_lanes,
11995 pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n,
11996 pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n,
11997 pipe_config->fdi_m_n.tu);
11998 DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11999 pipe_config->has_dp_encoder,
12000 pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n,
12001 pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n,
12002 pipe_config->dp_m_n.tu);
12004 DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
12005 pipe_config->has_dp_encoder,
12006 pipe_config->dp_m2_n2.gmch_m,
12007 pipe_config->dp_m2_n2.gmch_n,
12008 pipe_config->dp_m2_n2.link_m,
12009 pipe_config->dp_m2_n2.link_n,
12010 pipe_config->dp_m2_n2.tu);
12012 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
12013 pipe_config->has_audio,
12014 pipe_config->has_infoframe);
12016 DRM_DEBUG_KMS("requested mode:\n");
12017 drm_mode_debug_printmodeline(&pipe_config->base.mode);
12018 DRM_DEBUG_KMS("adjusted mode:\n");
12019 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
12020 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
12021 DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock);
12022 DRM_DEBUG_KMS("pipe src size: %dx%d\n",
12023 pipe_config->pipe_src_w, pipe_config->pipe_src_h);
12024 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
12026 pipe_config->scaler_state.scaler_users,
12027 pipe_config->scaler_state.scaler_id);
12028 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
12029 pipe_config->gmch_pfit.control,
12030 pipe_config->gmch_pfit.pgm_ratios,
12031 pipe_config->gmch_pfit.lvds_border_bits);
12032 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
12033 pipe_config->pch_pfit.pos,
12034 pipe_config->pch_pfit.size,
12035 pipe_config->pch_pfit.enabled ? "enabled" : "disabled");
12036 DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled);
12037 DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide);
12039 if (IS_BROXTON(dev)) {
12040 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x,"
12041 "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, "
12042 "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n",
12043 pipe_config->ddi_pll_sel,
12044 pipe_config->dpll_hw_state.ebb0,
12045 pipe_config->dpll_hw_state.ebb4,
12046 pipe_config->dpll_hw_state.pll0,
12047 pipe_config->dpll_hw_state.pll1,
12048 pipe_config->dpll_hw_state.pll2,
12049 pipe_config->dpll_hw_state.pll3,
12050 pipe_config->dpll_hw_state.pll6,
12051 pipe_config->dpll_hw_state.pll8,
12052 pipe_config->dpll_hw_state.pll9,
12053 pipe_config->dpll_hw_state.pll10,
12054 pipe_config->dpll_hw_state.pcsdw12);
12055 } else if (IS_SKYLAKE(dev)) {
12056 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: "
12057 "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n",
12058 pipe_config->ddi_pll_sel,
12059 pipe_config->dpll_hw_state.ctrl1,
12060 pipe_config->dpll_hw_state.cfgcr1,
12061 pipe_config->dpll_hw_state.cfgcr2);
12062 } else if (HAS_DDI(dev)) {
12063 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: wrpll: 0x%x\n",
12064 pipe_config->ddi_pll_sel,
12065 pipe_config->dpll_hw_state.wrpll);
12067 DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, "
12068 "fp0: 0x%x, fp1: 0x%x\n",
12069 pipe_config->dpll_hw_state.dpll,
12070 pipe_config->dpll_hw_state.dpll_md,
12071 pipe_config->dpll_hw_state.fp0,
12072 pipe_config->dpll_hw_state.fp1);
12075 DRM_DEBUG_KMS("planes on this crtc\n");
12076 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
12077 intel_plane = to_intel_plane(plane);
12078 if (intel_plane->pipe != crtc->pipe)
12081 state = to_intel_plane_state(plane->state);
12082 fb = state->base.fb;
12084 DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d "
12085 "disabled, scaler_id = %d\n",
12086 plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD",
12087 plane->base.id, intel_plane->pipe,
12088 (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1,
12089 drm_plane_index(plane), state->scaler_id);
12093 DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled",
12094 plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD",
12095 plane->base.id, intel_plane->pipe,
12096 crtc->base.primary == plane ? 0 : intel_plane->plane + 1,
12097 drm_plane_index(plane));
12098 DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x",
12099 fb->base.id, fb->width, fb->height, fb->pixel_format);
12100 DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n",
12102 state->src.x1 >> 16, state->src.y1 >> 16,
12103 drm_rect_width(&state->src) >> 16,
12104 drm_rect_height(&state->src) >> 16,
12105 state->dst.x1, state->dst.y1,
12106 drm_rect_width(&state->dst), drm_rect_height(&state->dst));
12110 static bool check_digital_port_conflicts(struct drm_atomic_state *state)
12112 struct drm_device *dev = state->dev;
12113 struct intel_encoder *encoder;
12114 struct drm_connector *connector;
12115 struct drm_connector_state *connector_state;
12116 unsigned int used_ports = 0;
12120 * Walk the connector list instead of the encoder
12121 * list to detect the problem on ddi platforms
12122 * where there's just one encoder per digital port.
12124 for_each_connector_in_state(state, connector, connector_state, i) {
12125 if (!connector_state->best_encoder)
12128 encoder = to_intel_encoder(connector_state->best_encoder);
12130 WARN_ON(!connector_state->crtc);
12132 switch (encoder->type) {
12133 unsigned int port_mask;
12134 case INTEL_OUTPUT_UNKNOWN:
12135 if (WARN_ON(!HAS_DDI(dev)))
12137 case INTEL_OUTPUT_DISPLAYPORT:
12138 case INTEL_OUTPUT_HDMI:
12139 case INTEL_OUTPUT_EDP:
12140 port_mask = 1 << enc_to_dig_port(&encoder->base)->port;
12142 /* the same port mustn't appear more than once */
12143 if (used_ports & port_mask)
12146 used_ports |= port_mask;
12156 clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
12158 struct drm_crtc_state tmp_state;
12159 struct intel_crtc_scaler_state scaler_state;
12160 struct intel_dpll_hw_state dpll_hw_state;
12161 enum intel_dpll_id shared_dpll;
12162 uint32_t ddi_pll_sel;
12164 /* FIXME: before the switch to atomic started, a new pipe_config was
12165 * kzalloc'd. Code that depends on any field being zero should be
12166 * fixed, so that the crtc_state can be safely duplicated. For now,
12167 * only fields that are know to not cause problems are preserved. */
12169 tmp_state = crtc_state->base;
12170 scaler_state = crtc_state->scaler_state;
12171 shared_dpll = crtc_state->shared_dpll;
12172 dpll_hw_state = crtc_state->dpll_hw_state;
12173 ddi_pll_sel = crtc_state->ddi_pll_sel;
12175 memset(crtc_state, 0, sizeof *crtc_state);
12177 crtc_state->base = tmp_state;
12178 crtc_state->scaler_state = scaler_state;
12179 crtc_state->shared_dpll = shared_dpll;
12180 crtc_state->dpll_hw_state = dpll_hw_state;
12181 crtc_state->ddi_pll_sel = ddi_pll_sel;
12185 intel_modeset_pipe_config(struct drm_crtc *crtc,
12186 struct intel_crtc_state *pipe_config)
12188 struct drm_atomic_state *state = pipe_config->base.state;
12189 struct intel_encoder *encoder;
12190 struct drm_connector *connector;
12191 struct drm_connector_state *connector_state;
12192 int base_bpp, ret = -EINVAL;
12196 clear_intel_crtc_state(pipe_config);
12198 pipe_config->cpu_transcoder =
12199 (enum transcoder) to_intel_crtc(crtc)->pipe;
12202 * Sanitize sync polarity flags based on requested ones. If neither
12203 * positive or negative polarity is requested, treat this as meaning
12204 * negative polarity.
12206 if (!(pipe_config->base.adjusted_mode.flags &
12207 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
12208 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
12210 if (!(pipe_config->base.adjusted_mode.flags &
12211 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
12212 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
12214 /* Compute a starting value for pipe_config->pipe_bpp taking the source
12215 * plane pixel format and any sink constraints into account. Returns the
12216 * source plane bpp so that dithering can be selected on mismatches
12217 * after encoders and crtc also have had their say. */
12218 base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
12224 * Determine the real pipe dimensions. Note that stereo modes can
12225 * increase the actual pipe size due to the frame doubling and
12226 * insertion of additional space for blanks between the frame. This
12227 * is stored in the crtc timings. We use the requested mode to do this
12228 * computation to clearly distinguish it from the adjusted mode, which
12229 * can be changed by the connectors in the below retry loop.
12231 drm_crtc_get_hv_timing(&pipe_config->base.mode,
12232 &pipe_config->pipe_src_w,
12233 &pipe_config->pipe_src_h);
12236 /* Ensure the port clock defaults are reset when retrying. */
12237 pipe_config->port_clock = 0;
12238 pipe_config->pixel_multiplier = 1;
12240 /* Fill in default crtc timings, allow encoders to overwrite them. */
12241 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
12242 CRTC_STEREO_DOUBLE);
12244 /* Pass our mode to the connectors and the CRTC to give them a chance to
12245 * adjust it according to limitations or connector properties, and also
12246 * a chance to reject the mode entirely.
12248 for_each_connector_in_state(state, connector, connector_state, i) {
12249 if (connector_state->crtc != crtc)
12252 encoder = to_intel_encoder(connector_state->best_encoder);
12254 if (!(encoder->compute_config(encoder, pipe_config))) {
12255 DRM_DEBUG_KMS("Encoder config failure\n");
12260 /* Set default port clock if not overwritten by the encoder. Needs to be
12261 * done afterwards in case the encoder adjusts the mode. */
12262 if (!pipe_config->port_clock)
12263 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
12264 * pipe_config->pixel_multiplier;
12266 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
12268 DRM_DEBUG_KMS("CRTC fixup failed\n");
12272 if (ret == RETRY) {
12273 if (WARN(!retry, "loop in pipe configuration computation\n")) {
12278 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
12280 goto encoder_retry;
12283 pipe_config->dither = pipe_config->pipe_bpp != base_bpp;
12284 DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
12285 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
12291 static bool intel_crtc_in_use(struct drm_crtc *crtc)
12293 struct drm_encoder *encoder;
12294 struct drm_device *dev = crtc->dev;
12296 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
12297 if (encoder->crtc == crtc)
12304 intel_modeset_update_state(struct drm_atomic_state *state)
12306 struct drm_device *dev = state->dev;
12307 struct intel_encoder *intel_encoder;
12308 struct drm_crtc *crtc;
12309 struct drm_crtc_state *crtc_state;
12310 struct drm_connector *connector;
12313 intel_shared_dpll_commit(state);
12315 for_each_intel_encoder(dev, intel_encoder) {
12316 if (!intel_encoder->base.crtc)
12319 crtc = intel_encoder->base.crtc;
12320 crtc_state = drm_atomic_get_existing_crtc_state(state, crtc);
12321 if (!crtc_state || !needs_modeset(crtc->state))
12324 intel_encoder->connectors_active = false;
12327 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
12329 /* Double check state. */
12330 for_each_crtc_in_state(state, crtc, crtc_state, i) {
12331 WARN_ON(crtc->state->enable != intel_crtc_in_use(crtc));
12333 to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state);
12335 /* Update hwmode for vblank functions */
12336 if (crtc->state->active)
12337 crtc->hwmode = crtc->state->adjusted_mode;
12339 crtc->hwmode.crtc_clock = 0;
12342 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
12343 if (!connector->encoder || !connector->encoder->crtc)
12346 crtc = connector->encoder->crtc;
12347 crtc_state = drm_atomic_get_existing_crtc_state(state, crtc);
12348 if (!crtc_state || !needs_modeset(crtc->state))
12351 if (crtc->state->active) {
12352 struct drm_property *dpms_property =
12353 dev->mode_config.dpms_property;
12355 connector->dpms = DRM_MODE_DPMS_ON;
12356 drm_object_property_set_value(&connector->base, dpms_property, DRM_MODE_DPMS_ON);
12358 intel_encoder = to_intel_encoder(connector->encoder);
12359 intel_encoder->connectors_active = true;
12361 connector->dpms = DRM_MODE_DPMS_OFF;
12365 static bool intel_fuzzy_clock_check(int clock1, int clock2)
12369 if (clock1 == clock2)
12372 if (!clock1 || !clock2)
12375 diff = abs(clock1 - clock2);
12377 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
12383 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
12384 list_for_each_entry((intel_crtc), \
12385 &(dev)->mode_config.crtc_list, \
12387 if (mask & (1 <<(intel_crtc)->pipe))
12391 intel_compare_m_n(unsigned int m, unsigned int n,
12392 unsigned int m2, unsigned int n2,
12395 if (m == m2 && n == n2)
12398 if (exact || !m || !n || !m2 || !n2)
12401 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
12408 } else if (m < m2) {
12415 return m == m2 && n == n2;
12419 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
12420 struct intel_link_m_n *m2_n2,
12423 if (m_n->tu == m2_n2->tu &&
12424 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
12425 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
12426 intel_compare_m_n(m_n->link_m, m_n->link_n,
12427 m2_n2->link_m, m2_n2->link_n, !adjust)) {
12438 intel_pipe_config_compare(struct drm_device *dev,
12439 struct intel_crtc_state *current_config,
12440 struct intel_crtc_state *pipe_config,
12445 #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \
12448 DRM_ERROR(fmt, ##__VA_ARGS__); \
12450 DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \
12453 #define PIPE_CONF_CHECK_X(name) \
12454 if (current_config->name != pipe_config->name) { \
12455 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12456 "(expected 0x%08x, found 0x%08x)\n", \
12457 current_config->name, \
12458 pipe_config->name); \
12462 #define PIPE_CONF_CHECK_I(name) \
12463 if (current_config->name != pipe_config->name) { \
12464 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12465 "(expected %i, found %i)\n", \
12466 current_config->name, \
12467 pipe_config->name); \
12471 #define PIPE_CONF_CHECK_M_N(name) \
12472 if (!intel_compare_link_m_n(¤t_config->name, \
12473 &pipe_config->name,\
12475 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12476 "(expected tu %i gmch %i/%i link %i/%i, " \
12477 "found tu %i, gmch %i/%i link %i/%i)\n", \
12478 current_config->name.tu, \
12479 current_config->name.gmch_m, \
12480 current_config->name.gmch_n, \
12481 current_config->name.link_m, \
12482 current_config->name.link_n, \
12483 pipe_config->name.tu, \
12484 pipe_config->name.gmch_m, \
12485 pipe_config->name.gmch_n, \
12486 pipe_config->name.link_m, \
12487 pipe_config->name.link_n); \
12491 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \
12492 if (!intel_compare_link_m_n(¤t_config->name, \
12493 &pipe_config->name, adjust) && \
12494 !intel_compare_link_m_n(¤t_config->alt_name, \
12495 &pipe_config->name, adjust)) { \
12496 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12497 "(expected tu %i gmch %i/%i link %i/%i, " \
12498 "or tu %i gmch %i/%i link %i/%i, " \
12499 "found tu %i, gmch %i/%i link %i/%i)\n", \
12500 current_config->name.tu, \
12501 current_config->name.gmch_m, \
12502 current_config->name.gmch_n, \
12503 current_config->name.link_m, \
12504 current_config->name.link_n, \
12505 current_config->alt_name.tu, \
12506 current_config->alt_name.gmch_m, \
12507 current_config->alt_name.gmch_n, \
12508 current_config->alt_name.link_m, \
12509 current_config->alt_name.link_n, \
12510 pipe_config->name.tu, \
12511 pipe_config->name.gmch_m, \
12512 pipe_config->name.gmch_n, \
12513 pipe_config->name.link_m, \
12514 pipe_config->name.link_n); \
12518 /* This is required for BDW+ where there is only one set of registers for
12519 * switching between high and low RR.
12520 * This macro can be used whenever a comparison has to be made between one
12521 * hw state and multiple sw state variables.
12523 #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \
12524 if ((current_config->name != pipe_config->name) && \
12525 (current_config->alt_name != pipe_config->name)) { \
12526 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12527 "(expected %i or %i, found %i)\n", \
12528 current_config->name, \
12529 current_config->alt_name, \
12530 pipe_config->name); \
12534 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
12535 if ((current_config->name ^ pipe_config->name) & (mask)) { \
12536 INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \
12537 "(expected %i, found %i)\n", \
12538 current_config->name & (mask), \
12539 pipe_config->name & (mask)); \
12543 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
12544 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
12545 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12546 "(expected %i, found %i)\n", \
12547 current_config->name, \
12548 pipe_config->name); \
12552 #define PIPE_CONF_QUIRK(quirk) \
12553 ((current_config->quirks | pipe_config->quirks) & (quirk))
12555 PIPE_CONF_CHECK_I(cpu_transcoder);
12557 PIPE_CONF_CHECK_I(has_pch_encoder);
12558 PIPE_CONF_CHECK_I(fdi_lanes);
12559 PIPE_CONF_CHECK_M_N(fdi_m_n);
12561 PIPE_CONF_CHECK_I(has_dp_encoder);
12563 if (INTEL_INFO(dev)->gen < 8) {
12564 PIPE_CONF_CHECK_M_N(dp_m_n);
12566 PIPE_CONF_CHECK_I(has_drrs);
12567 if (current_config->has_drrs)
12568 PIPE_CONF_CHECK_M_N(dp_m2_n2);
12570 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
12572 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
12573 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
12574 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
12575 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
12576 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
12577 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
12579 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
12580 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
12581 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
12582 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
12583 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
12584 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
12586 PIPE_CONF_CHECK_I(pixel_multiplier);
12587 PIPE_CONF_CHECK_I(has_hdmi_sink);
12588 if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) ||
12589 IS_VALLEYVIEW(dev))
12590 PIPE_CONF_CHECK_I(limited_color_range);
12591 PIPE_CONF_CHECK_I(has_infoframe);
12593 PIPE_CONF_CHECK_I(has_audio);
12595 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12596 DRM_MODE_FLAG_INTERLACE);
12598 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
12599 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12600 DRM_MODE_FLAG_PHSYNC);
12601 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12602 DRM_MODE_FLAG_NHSYNC);
12603 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12604 DRM_MODE_FLAG_PVSYNC);
12605 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12606 DRM_MODE_FLAG_NVSYNC);
12609 PIPE_CONF_CHECK_I(pipe_src_w);
12610 PIPE_CONF_CHECK_I(pipe_src_h);
12613 * FIXME: BIOS likes to set up a cloned config with lvds+external
12614 * screen. Since we don't yet re-compute the pipe config when moving
12615 * just the lvds port away to another pipe the sw tracking won't match.
12617 * Proper atomic modesets with recomputed global state will fix this.
12618 * Until then just don't check gmch state for inherited modes.
12620 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) {
12621 PIPE_CONF_CHECK_I(gmch_pfit.control);
12622 /* pfit ratios are autocomputed by the hw on gen4+ */
12623 if (INTEL_INFO(dev)->gen < 4)
12624 PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios);
12625 PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits);
12628 PIPE_CONF_CHECK_I(pch_pfit.enabled);
12629 if (current_config->pch_pfit.enabled) {
12630 PIPE_CONF_CHECK_I(pch_pfit.pos);
12631 PIPE_CONF_CHECK_I(pch_pfit.size);
12634 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
12636 /* BDW+ don't expose a synchronous way to read the state */
12637 if (IS_HASWELL(dev))
12638 PIPE_CONF_CHECK_I(ips_enabled);
12640 PIPE_CONF_CHECK_I(double_wide);
12642 PIPE_CONF_CHECK_X(ddi_pll_sel);
12644 PIPE_CONF_CHECK_I(shared_dpll);
12645 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
12646 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
12647 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
12648 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
12649 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
12650 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
12651 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
12652 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
12654 if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5)
12655 PIPE_CONF_CHECK_I(pipe_bpp);
12657 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
12658 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
12660 #undef PIPE_CONF_CHECK_X
12661 #undef PIPE_CONF_CHECK_I
12662 #undef PIPE_CONF_CHECK_I_ALT
12663 #undef PIPE_CONF_CHECK_FLAGS
12664 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
12665 #undef PIPE_CONF_QUIRK
12666 #undef INTEL_ERR_OR_DBG_KMS
12671 static void check_wm_state(struct drm_device *dev)
12673 struct drm_i915_private *dev_priv = dev->dev_private;
12674 struct skl_ddb_allocation hw_ddb, *sw_ddb;
12675 struct intel_crtc *intel_crtc;
12678 if (INTEL_INFO(dev)->gen < 9)
12681 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
12682 sw_ddb = &dev_priv->wm.skl_hw.ddb;
12684 for_each_intel_crtc(dev, intel_crtc) {
12685 struct skl_ddb_entry *hw_entry, *sw_entry;
12686 const enum pipe pipe = intel_crtc->pipe;
12688 if (!intel_crtc->active)
12692 for_each_plane(dev_priv, pipe, plane) {
12693 hw_entry = &hw_ddb.plane[pipe][plane];
12694 sw_entry = &sw_ddb->plane[pipe][plane];
12696 if (skl_ddb_entry_equal(hw_entry, sw_entry))
12699 DRM_ERROR("mismatch in DDB state pipe %c plane %d "
12700 "(expected (%u,%u), found (%u,%u))\n",
12701 pipe_name(pipe), plane + 1,
12702 sw_entry->start, sw_entry->end,
12703 hw_entry->start, hw_entry->end);
12707 hw_entry = &hw_ddb.cursor[pipe];
12708 sw_entry = &sw_ddb->cursor[pipe];
12710 if (skl_ddb_entry_equal(hw_entry, sw_entry))
12713 DRM_ERROR("mismatch in DDB state pipe %c cursor "
12714 "(expected (%u,%u), found (%u,%u))\n",
12716 sw_entry->start, sw_entry->end,
12717 hw_entry->start, hw_entry->end);
12722 check_connector_state(struct drm_device *dev)
12724 struct intel_connector *connector;
12726 for_each_intel_connector(dev, connector) {
12727 struct drm_encoder *encoder = connector->base.encoder;
12728 struct drm_connector_state *state = connector->base.state;
12730 /* This also checks the encoder/connector hw state with the
12731 * ->get_hw_state callbacks. */
12732 intel_connector_check_state(connector);
12734 I915_STATE_WARN(state->best_encoder != encoder,
12735 "connector's staged encoder doesn't match current encoder\n");
12740 check_encoder_state(struct drm_device *dev)
12742 struct intel_encoder *encoder;
12743 struct intel_connector *connector;
12745 for_each_intel_encoder(dev, encoder) {
12746 bool enabled = false;
12747 bool active = false;
12748 enum pipe pipe, tracked_pipe;
12750 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
12751 encoder->base.base.id,
12752 encoder->base.name);
12754 I915_STATE_WARN(encoder->connectors_active && !encoder->base.crtc,
12755 "encoder's active_connectors set, but no crtc\n");
12757 for_each_intel_connector(dev, connector) {
12758 if (connector->base.encoder != &encoder->base)
12761 if (connector->base.dpms != DRM_MODE_DPMS_OFF)
12764 I915_STATE_WARN(connector->base.state->crtc !=
12765 encoder->base.crtc,
12766 "connector's crtc doesn't match encoder crtc\n");
12769 * for MST connectors if we unplug the connector is gone
12770 * away but the encoder is still connected to a crtc
12771 * until a modeset happens in response to the hotplug.
12773 if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST)
12776 I915_STATE_WARN(!!encoder->base.crtc != enabled,
12777 "encoder's enabled state mismatch "
12778 "(expected %i, found %i)\n",
12779 !!encoder->base.crtc, enabled);
12780 I915_STATE_WARN(active && !encoder->base.crtc,
12781 "active encoder with no crtc\n");
12783 I915_STATE_WARN(encoder->connectors_active != active,
12784 "encoder's computed active state doesn't match tracked active state "
12785 "(expected %i, found %i)\n", active, encoder->connectors_active);
12787 active = encoder->get_hw_state(encoder, &pipe);
12788 I915_STATE_WARN(active != encoder->connectors_active,
12789 "encoder's hw state doesn't match sw tracking "
12790 "(expected %i, found %i)\n",
12791 encoder->connectors_active, active);
12793 if (!encoder->base.crtc)
12796 tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
12797 I915_STATE_WARN(active && pipe != tracked_pipe,
12798 "active encoder's pipe doesn't match"
12799 "(expected %i, found %i)\n",
12800 tracked_pipe, pipe);
12806 check_crtc_state(struct drm_device *dev)
12808 struct drm_i915_private *dev_priv = dev->dev_private;
12809 struct intel_crtc *crtc;
12810 struct intel_encoder *encoder;
12811 struct intel_crtc_state pipe_config;
12813 for_each_intel_crtc(dev, crtc) {
12814 bool enabled = false;
12815 bool active = false;
12817 memset(&pipe_config, 0, sizeof(pipe_config));
12819 DRM_DEBUG_KMS("[CRTC:%d]\n",
12820 crtc->base.base.id);
12822 I915_STATE_WARN(crtc->active && !crtc->base.state->enable,
12823 "active crtc, but not enabled in sw tracking\n");
12825 for_each_intel_encoder(dev, encoder) {
12826 if (encoder->base.crtc != &crtc->base)
12829 if (encoder->connectors_active)
12833 I915_STATE_WARN(active != crtc->active,
12834 "crtc's computed active state doesn't match tracked active state "
12835 "(expected %i, found %i)\n", active, crtc->active);
12836 I915_STATE_WARN(enabled != crtc->base.state->enable,
12837 "crtc's computed enabled state doesn't match tracked enabled state "
12838 "(expected %i, found %i)\n", enabled,
12839 crtc->base.state->enable);
12841 active = dev_priv->display.get_pipe_config(crtc,
12844 /* hw state is inconsistent with the pipe quirk */
12845 if ((crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
12846 (crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
12847 active = crtc->active;
12849 for_each_intel_encoder(dev, encoder) {
12851 if (encoder->base.crtc != &crtc->base)
12853 if (encoder->get_hw_state(encoder, &pipe))
12854 encoder->get_config(encoder, &pipe_config);
12857 I915_STATE_WARN(crtc->active != active,
12858 "crtc active state doesn't match with hw state "
12859 "(expected %i, found %i)\n", crtc->active, active);
12861 I915_STATE_WARN(crtc->active != crtc->base.state->active,
12862 "transitional active state does not match atomic hw state "
12863 "(expected %i, found %i)\n", crtc->base.state->active, crtc->active);
12868 if (!intel_pipe_config_compare(dev, crtc->config,
12869 &pipe_config, false)) {
12870 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12871 intel_dump_pipe_config(crtc, &pipe_config,
12873 intel_dump_pipe_config(crtc, crtc->config,
12880 check_shared_dpll_state(struct drm_device *dev)
12882 struct drm_i915_private *dev_priv = dev->dev_private;
12883 struct intel_crtc *crtc;
12884 struct intel_dpll_hw_state dpll_hw_state;
12887 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
12888 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
12889 int enabled_crtcs = 0, active_crtcs = 0;
12892 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
12894 DRM_DEBUG_KMS("%s\n", pll->name);
12896 active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state);
12898 I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask),
12899 "more active pll users than references: %i vs %i\n",
12900 pll->active, hweight32(pll->config.crtc_mask));
12901 I915_STATE_WARN(pll->active && !pll->on,
12902 "pll in active use but not on in sw tracking\n");
12903 I915_STATE_WARN(pll->on && !pll->active,
12904 "pll in on but not on in use in sw tracking\n");
12905 I915_STATE_WARN(pll->on != active,
12906 "pll on state mismatch (expected %i, found %i)\n",
12909 for_each_intel_crtc(dev, crtc) {
12910 if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll)
12912 if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
12915 I915_STATE_WARN(pll->active != active_crtcs,
12916 "pll active crtcs mismatch (expected %i, found %i)\n",
12917 pll->active, active_crtcs);
12918 I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs,
12919 "pll enabled crtcs mismatch (expected %i, found %i)\n",
12920 hweight32(pll->config.crtc_mask), enabled_crtcs);
12922 I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, &dpll_hw_state,
12923 sizeof(dpll_hw_state)),
12924 "pll hw state mismatch\n");
12929 intel_modeset_check_state(struct drm_device *dev)
12931 check_wm_state(dev);
12932 check_connector_state(dev);
12933 check_encoder_state(dev);
12934 check_crtc_state(dev);
12935 check_shared_dpll_state(dev);
12938 void ironlake_check_encoder_dotclock(const struct intel_crtc_state *pipe_config,
12942 * FDI already provided one idea for the dotclock.
12943 * Yell if the encoder disagrees.
12945 WARN(!intel_fuzzy_clock_check(pipe_config->base.adjusted_mode.crtc_clock, dotclock),
12946 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
12947 pipe_config->base.adjusted_mode.crtc_clock, dotclock);
12950 static void update_scanline_offset(struct intel_crtc *crtc)
12952 struct drm_device *dev = crtc->base.dev;
12955 * The scanline counter increments at the leading edge of hsync.
12957 * On most platforms it starts counting from vtotal-1 on the
12958 * first active line. That means the scanline counter value is
12959 * always one less than what we would expect. Ie. just after
12960 * start of vblank, which also occurs at start of hsync (on the
12961 * last active line), the scanline counter will read vblank_start-1.
12963 * On gen2 the scanline counter starts counting from 1 instead
12964 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12965 * to keep the value positive), instead of adding one.
12967 * On HSW+ the behaviour of the scanline counter depends on the output
12968 * type. For DP ports it behaves like most other platforms, but on HDMI
12969 * there's an extra 1 line difference. So we need to add two instead of
12970 * one to the value.
12972 if (IS_GEN2(dev)) {
12973 const struct drm_display_mode *mode = &crtc->config->base.adjusted_mode;
12976 vtotal = mode->crtc_vtotal;
12977 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
12980 crtc->scanline_offset = vtotal - 1;
12981 } else if (HAS_DDI(dev) &&
12982 intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) {
12983 crtc->scanline_offset = 2;
12985 crtc->scanline_offset = 1;
12988 static void intel_modeset_clear_plls(struct drm_atomic_state *state)
12990 struct drm_device *dev = state->dev;
12991 struct drm_i915_private *dev_priv = to_i915(dev);
12992 struct intel_shared_dpll_config *shared_dpll = NULL;
12993 struct intel_crtc *intel_crtc;
12994 struct intel_crtc_state *intel_crtc_state;
12995 struct drm_crtc *crtc;
12996 struct drm_crtc_state *crtc_state;
12999 if (!dev_priv->display.crtc_compute_clock)
13002 for_each_crtc_in_state(state, crtc, crtc_state, i) {
13005 intel_crtc = to_intel_crtc(crtc);
13006 intel_crtc_state = to_intel_crtc_state(crtc_state);
13007 dpll = intel_crtc_state->shared_dpll;
13009 if (!needs_modeset(crtc_state) || dpll == DPLL_ID_PRIVATE)
13012 intel_crtc_state->shared_dpll = DPLL_ID_PRIVATE;
13015 shared_dpll = intel_atomic_get_shared_dpll_state(state);
13017 shared_dpll[dpll].crtc_mask &= ~(1 << intel_crtc->pipe);
13022 * This implements the workaround described in the "notes" section of the mode
13023 * set sequence documentation. When going from no pipes or single pipe to
13024 * multiple pipes, and planes are enabled after the pipe, we need to wait at
13025 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
13027 static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
13029 struct drm_crtc_state *crtc_state;
13030 struct intel_crtc *intel_crtc;
13031 struct drm_crtc *crtc;
13032 struct intel_crtc_state *first_crtc_state = NULL;
13033 struct intel_crtc_state *other_crtc_state = NULL;
13034 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
13037 /* look at all crtc's that are going to be enabled in during modeset */
13038 for_each_crtc_in_state(state, crtc, crtc_state, i) {
13039 intel_crtc = to_intel_crtc(crtc);
13041 if (!crtc_state->active || !needs_modeset(crtc_state))
13044 if (first_crtc_state) {
13045 other_crtc_state = to_intel_crtc_state(crtc_state);
13048 first_crtc_state = to_intel_crtc_state(crtc_state);
13049 first_pipe = intel_crtc->pipe;
13053 /* No workaround needed? */
13054 if (!first_crtc_state)
13057 /* w/a possibly needed, check how many crtc's are already enabled. */
13058 for_each_intel_crtc(state->dev, intel_crtc) {
13059 struct intel_crtc_state *pipe_config;
13061 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
13062 if (IS_ERR(pipe_config))
13063 return PTR_ERR(pipe_config);
13065 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
13067 if (!pipe_config->base.active ||
13068 needs_modeset(&pipe_config->base))
13071 /* 2 or more enabled crtcs means no need for w/a */
13072 if (enabled_pipe != INVALID_PIPE)
13075 enabled_pipe = intel_crtc->pipe;
13078 if (enabled_pipe != INVALID_PIPE)
13079 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
13080 else if (other_crtc_state)
13081 other_crtc_state->hsw_workaround_pipe = first_pipe;
13086 static int intel_modeset_all_pipes(struct drm_atomic_state *state)
13088 struct drm_crtc *crtc;
13089 struct drm_crtc_state *crtc_state;
13092 /* add all active pipes to the state */
13093 for_each_crtc(state->dev, crtc) {
13094 crtc_state = drm_atomic_get_crtc_state(state, crtc);
13095 if (IS_ERR(crtc_state))
13096 return PTR_ERR(crtc_state);
13098 if (!crtc_state->active || needs_modeset(crtc_state))
13101 crtc_state->mode_changed = true;
13103 ret = drm_atomic_add_affected_connectors(state, crtc);
13107 ret = drm_atomic_add_affected_planes(state, crtc);
13116 /* Code that should eventually be part of atomic_check() */
13117 static int intel_modeset_checks(struct drm_atomic_state *state)
13119 struct drm_device *dev = state->dev;
13120 struct drm_i915_private *dev_priv = dev->dev_private;
13123 if (!check_digital_port_conflicts(state)) {
13124 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
13129 * See if the config requires any additional preparation, e.g.
13130 * to adjust global state with pipes off. We need to do this
13131 * here so we can get the modeset_pipe updated config for the new
13132 * mode set on this crtc. For other crtcs we need to use the
13133 * adjusted_mode bits in the crtc directly.
13135 if (dev_priv->display.modeset_calc_cdclk) {
13136 unsigned int cdclk;
13138 ret = dev_priv->display.modeset_calc_cdclk(state);
13140 cdclk = to_intel_atomic_state(state)->cdclk;
13141 if (!ret && cdclk != dev_priv->cdclk_freq)
13142 ret = intel_modeset_all_pipes(state);
13147 to_intel_atomic_state(state)->cdclk = dev_priv->cdclk_freq;
13149 intel_modeset_clear_plls(state);
13151 if (IS_HASWELL(dev))
13152 return haswell_mode_set_planes_workaround(state);
13158 intel_modeset_compute_config(struct drm_atomic_state *state)
13160 struct drm_crtc *crtc;
13161 struct drm_crtc_state *crtc_state;
13163 bool any_ms = false;
13165 ret = drm_atomic_helper_check_modeset(state->dev, state);
13169 for_each_crtc_in_state(state, crtc, crtc_state, i) {
13170 struct intel_crtc_state *pipe_config =
13171 to_intel_crtc_state(crtc_state);
13172 bool modeset, recalc = false;
13174 if (!crtc_state->enable) {
13175 if (needs_modeset(crtc_state))
13180 modeset = needs_modeset(crtc_state);
13181 /* see comment in intel_modeset_readout_hw_state */
13182 if (!modeset && crtc_state->mode_blob != crtc->state->mode_blob &&
13183 pipe_config->quirks & PIPE_CONFIG_QUIRK_INHERITED_MODE)
13186 if (!modeset && !recalc)
13190 ret = drm_atomic_add_affected_connectors(state, crtc);
13195 ret = intel_modeset_pipe_config(crtc, pipe_config);
13199 if (recalc && (!i915.fastboot ||
13200 !intel_pipe_config_compare(state->dev,
13201 to_intel_crtc_state(crtc->state),
13202 pipe_config, true))) {
13203 modeset = crtc_state->mode_changed = true;
13205 ret = drm_atomic_add_affected_planes(state, crtc);
13211 intel_dump_pipe_config(to_intel_crtc(crtc),
13213 modeset ? "[modeset]" : "[fastboot]");
13217 ret = intel_modeset_checks(state);
13222 to_intel_atomic_state(state)->cdclk =
13223 to_i915(state->dev)->cdclk_freq;
13225 return drm_atomic_helper_check_planes(state->dev, state);
13228 static int __intel_set_mode(struct drm_atomic_state *state)
13230 struct drm_device *dev = state->dev;
13231 struct drm_i915_private *dev_priv = dev->dev_private;
13232 struct drm_crtc *crtc;
13233 struct drm_crtc_state *crtc_state;
13236 bool any_ms = false;
13238 ret = drm_atomic_helper_prepare_planes(dev, state);
13242 drm_atomic_helper_swap_state(dev, state);
13244 for_each_crtc_in_state(state, crtc, crtc_state, i) {
13245 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13247 if (!needs_modeset(crtc->state))
13251 intel_pre_plane_update(intel_crtc);
13253 if (crtc_state->active) {
13254 intel_crtc_disable_planes(crtc, crtc_state->plane_mask);
13255 dev_priv->display.crtc_disable(crtc);
13256 intel_crtc->active = false;
13257 intel_disable_shared_dpll(intel_crtc);
13261 /* Only after disabling all output pipelines that will be changed can we
13262 * update the the output configuration. */
13263 intel_modeset_update_state(state);
13265 /* The state has been swaped above, so state actually contains the
13266 * old state now. */
13268 modeset_update_crtc_power_domains(state);
13270 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
13271 for_each_crtc_in_state(state, crtc, crtc_state, i) {
13272 if (needs_modeset(crtc->state) && crtc->state->active) {
13273 update_scanline_offset(to_intel_crtc(crtc));
13274 dev_priv->display.crtc_enable(crtc);
13277 drm_atomic_helper_commit_planes_on_crtc(crtc_state);
13280 /* FIXME: add subpixel order */
13282 drm_atomic_helper_cleanup_planes(dev, state);
13284 drm_atomic_state_free(state);
13289 static int intel_set_mode_checked(struct drm_atomic_state *state)
13291 struct drm_device *dev = state->dev;
13294 ret = __intel_set_mode(state);
13296 intel_modeset_check_state(dev);
13301 static int intel_set_mode(struct drm_atomic_state *state)
13305 ret = intel_modeset_compute_config(state);
13309 return intel_set_mode_checked(state);
13312 void intel_crtc_restore_mode(struct drm_crtc *crtc)
13314 struct drm_device *dev = crtc->dev;
13315 struct drm_atomic_state *state;
13316 struct drm_crtc_state *crtc_state;
13319 state = drm_atomic_state_alloc(dev);
13321 DRM_DEBUG_KMS("[CRTC:%d] crtc restore failed, out of memory",
13326 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
13329 crtc_state = drm_atomic_get_crtc_state(state, crtc);
13330 ret = PTR_ERR_OR_ZERO(crtc_state);
13332 if (!crtc_state->active)
13335 crtc_state->mode_changed = true;
13336 ret = intel_set_mode(state);
13339 if (ret == -EDEADLK) {
13340 drm_atomic_state_clear(state);
13341 drm_modeset_backoff(state->acquire_ctx);
13347 drm_atomic_state_free(state);
13350 #undef for_each_intel_crtc_masked
13352 static bool intel_connector_in_mode_set(struct intel_connector *connector,
13353 struct drm_mode_set *set)
13357 for (ro = 0; ro < set->num_connectors; ro++)
13358 if (set->connectors[ro] == &connector->base)
13365 intel_modeset_stage_output_state(struct drm_device *dev,
13366 struct drm_mode_set *set,
13367 struct drm_atomic_state *state)
13369 struct intel_connector *connector;
13370 struct drm_connector *drm_connector;
13371 struct drm_connector_state *connector_state;
13372 struct drm_crtc *crtc;
13373 struct drm_crtc_state *crtc_state;
13376 /* The upper layers ensure that we either disable a crtc or have a list
13377 * of connectors. For paranoia, double-check this. */
13378 WARN_ON(!set->fb && (set->num_connectors != 0));
13379 WARN_ON(set->fb && (set->num_connectors == 0));
13381 for_each_intel_connector(dev, connector) {
13382 bool in_mode_set = intel_connector_in_mode_set(connector, set);
13384 if (!in_mode_set && connector->base.state->crtc != set->crtc)
13388 drm_atomic_get_connector_state(state, &connector->base);
13389 if (IS_ERR(connector_state))
13390 return PTR_ERR(connector_state);
13393 int pipe = to_intel_crtc(set->crtc)->pipe;
13394 connector_state->best_encoder =
13395 &intel_find_encoder(connector, pipe)->base;
13398 if (connector->base.state->crtc != set->crtc)
13401 /* If we disable the crtc, disable all its connectors. Also, if
13402 * the connector is on the changing crtc but not on the new
13403 * connector list, disable it. */
13404 if (!set->fb || !in_mode_set) {
13405 connector_state->best_encoder = NULL;
13407 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
13408 connector->base.base.id,
13409 connector->base.name);
13412 /* connector->new_encoder is now updated for all connectors. */
13414 for_each_connector_in_state(state, drm_connector, connector_state, i) {
13415 connector = to_intel_connector(drm_connector);
13417 if (!connector_state->best_encoder) {
13418 ret = drm_atomic_set_crtc_for_connector(connector_state,
13426 if (intel_connector_in_mode_set(connector, set)) {
13427 struct drm_crtc *crtc = connector->base.state->crtc;
13429 /* If this connector was in a previous crtc, add it
13430 * to the state. We might need to disable it. */
13433 drm_atomic_get_crtc_state(state, crtc);
13434 if (IS_ERR(crtc_state))
13435 return PTR_ERR(crtc_state);
13438 ret = drm_atomic_set_crtc_for_connector(connector_state,
13444 /* Make sure the new CRTC will work with the encoder */
13445 if (!drm_encoder_crtc_ok(connector_state->best_encoder,
13446 connector_state->crtc)) {
13450 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
13451 connector->base.base.id,
13452 connector->base.name,
13453 connector_state->crtc->base.id);
13455 if (connector_state->best_encoder != &connector->encoder->base)
13456 connector->encoder =
13457 to_intel_encoder(connector_state->best_encoder);
13460 for_each_crtc_in_state(state, crtc, crtc_state, i) {
13461 bool has_connectors;
13463 ret = drm_atomic_add_affected_connectors(state, crtc);
13467 has_connectors = !!drm_atomic_connectors_for_crtc(state, crtc);
13468 if (has_connectors != crtc_state->enable)
13469 crtc_state->enable =
13470 crtc_state->active = has_connectors;
13473 ret = intel_modeset_setup_plane_state(state, set->crtc, set->mode,
13474 set->fb, set->x, set->y);
13478 crtc_state = drm_atomic_get_crtc_state(state, set->crtc);
13479 if (IS_ERR(crtc_state))
13480 return PTR_ERR(crtc_state);
13482 ret = drm_atomic_set_mode_for_crtc(crtc_state, set->mode);
13486 if (set->num_connectors)
13487 crtc_state->active = true;
13492 static int intel_crtc_set_config(struct drm_mode_set *set)
13494 struct drm_device *dev;
13495 struct drm_atomic_state *state = NULL;
13499 BUG_ON(!set->crtc);
13500 BUG_ON(!set->crtc->helper_private);
13502 /* Enforce sane interface api - has been abused by the fb helper. */
13503 BUG_ON(!set->mode && set->fb);
13504 BUG_ON(set->fb && set->num_connectors == 0);
13507 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
13508 set->crtc->base.id, set->fb->base.id,
13509 (int)set->num_connectors, set->x, set->y);
13511 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
13514 dev = set->crtc->dev;
13516 state = drm_atomic_state_alloc(dev);
13520 state->acquire_ctx = dev->mode_config.acquire_ctx;
13522 ret = intel_modeset_stage_output_state(dev, set, state);
13526 ret = intel_modeset_compute_config(state);
13530 intel_update_pipe_size(to_intel_crtc(set->crtc));
13532 ret = intel_set_mode_checked(state);
13534 DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
13535 set->crtc->base.id, ret);
13540 drm_atomic_state_free(state);
13544 static const struct drm_crtc_funcs intel_crtc_funcs = {
13545 .gamma_set = intel_crtc_gamma_set,
13546 .set_config = intel_crtc_set_config,
13547 .destroy = intel_crtc_destroy,
13548 .page_flip = intel_crtc_page_flip,
13549 .atomic_duplicate_state = intel_crtc_duplicate_state,
13550 .atomic_destroy_state = intel_crtc_destroy_state,
13553 static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv,
13554 struct intel_shared_dpll *pll,
13555 struct intel_dpll_hw_state *hw_state)
13559 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS))
13562 val = I915_READ(PCH_DPLL(pll->id));
13563 hw_state->dpll = val;
13564 hw_state->fp0 = I915_READ(PCH_FP0(pll->id));
13565 hw_state->fp1 = I915_READ(PCH_FP1(pll->id));
13567 return val & DPLL_VCO_ENABLE;
13570 static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv,
13571 struct intel_shared_dpll *pll)
13573 I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0);
13574 I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1);
13577 static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv,
13578 struct intel_shared_dpll *pll)
13580 /* PCH refclock must be enabled first */
13581 ibx_assert_pch_refclk_enabled(dev_priv);
13583 I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll);
13585 /* Wait for the clocks to stabilize. */
13586 POSTING_READ(PCH_DPLL(pll->id));
13589 /* The pixel multiplier can only be updated once the
13590 * DPLL is enabled and the clocks are stable.
13592 * So write it again.
13594 I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll);
13595 POSTING_READ(PCH_DPLL(pll->id));
13599 static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv,
13600 struct intel_shared_dpll *pll)
13602 struct drm_device *dev = dev_priv->dev;
13603 struct intel_crtc *crtc;
13605 /* Make sure no transcoder isn't still depending on us. */
13606 for_each_intel_crtc(dev, crtc) {
13607 if (intel_crtc_to_shared_dpll(crtc) == pll)
13608 assert_pch_transcoder_disabled(dev_priv, crtc->pipe);
13611 I915_WRITE(PCH_DPLL(pll->id), 0);
13612 POSTING_READ(PCH_DPLL(pll->id));
13616 static char *ibx_pch_dpll_names[] = {
13621 static void ibx_pch_dpll_init(struct drm_device *dev)
13623 struct drm_i915_private *dev_priv = dev->dev_private;
13626 dev_priv->num_shared_dpll = 2;
13628 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
13629 dev_priv->shared_dplls[i].id = i;
13630 dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i];
13631 dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set;
13632 dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable;
13633 dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable;
13634 dev_priv->shared_dplls[i].get_hw_state =
13635 ibx_pch_dpll_get_hw_state;
13639 static void intel_shared_dpll_init(struct drm_device *dev)
13641 struct drm_i915_private *dev_priv = dev->dev_private;
13643 intel_update_cdclk(dev);
13646 intel_ddi_pll_init(dev);
13647 else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
13648 ibx_pch_dpll_init(dev);
13650 dev_priv->num_shared_dpll = 0;
13652 BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS);
13656 * intel_prepare_plane_fb - Prepare fb for usage on plane
13657 * @plane: drm plane to prepare for
13658 * @fb: framebuffer to prepare for presentation
13660 * Prepares a framebuffer for usage on a display plane. Generally this
13661 * involves pinning the underlying object and updating the frontbuffer tracking
13662 * bits. Some older platforms need special physical address handling for
13665 * Returns 0 on success, negative error code on failure.
13668 intel_prepare_plane_fb(struct drm_plane *plane,
13669 struct drm_framebuffer *fb,
13670 const struct drm_plane_state *new_state)
13672 struct drm_device *dev = plane->dev;
13673 struct intel_plane *intel_plane = to_intel_plane(plane);
13674 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13675 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
13681 mutex_lock(&dev->struct_mutex);
13683 if (plane->type == DRM_PLANE_TYPE_CURSOR &&
13684 INTEL_INFO(dev)->cursor_needs_physical) {
13685 int align = IS_I830(dev) ? 16 * 1024 : 256;
13686 ret = i915_gem_object_attach_phys(obj, align);
13688 DRM_DEBUG_KMS("failed to attach phys object\n");
13690 ret = intel_pin_and_fence_fb_obj(plane, fb, new_state, NULL, NULL);
13694 i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit);
13696 mutex_unlock(&dev->struct_mutex);
13702 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13703 * @plane: drm plane to clean up for
13704 * @fb: old framebuffer that was on plane
13706 * Cleans up a framebuffer that has just been removed from a plane.
13709 intel_cleanup_plane_fb(struct drm_plane *plane,
13710 struct drm_framebuffer *fb,
13711 const struct drm_plane_state *old_state)
13713 struct drm_device *dev = plane->dev;
13714 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13719 if (plane->type != DRM_PLANE_TYPE_CURSOR ||
13720 !INTEL_INFO(dev)->cursor_needs_physical) {
13721 mutex_lock(&dev->struct_mutex);
13722 intel_unpin_fb_obj(fb, old_state);
13723 mutex_unlock(&dev->struct_mutex);
13728 skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state)
13731 struct drm_device *dev;
13732 struct drm_i915_private *dev_priv;
13733 int crtc_clock, cdclk;
13735 if (!intel_crtc || !crtc_state)
13736 return DRM_PLANE_HELPER_NO_SCALING;
13738 dev = intel_crtc->base.dev;
13739 dev_priv = dev->dev_private;
13740 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
13741 cdclk = to_intel_atomic_state(crtc_state->base.state)->cdclk;
13743 if (!crtc_clock || !cdclk)
13744 return DRM_PLANE_HELPER_NO_SCALING;
13747 * skl max scale is lower of:
13748 * close to 3 but not 3, -1 is for that purpose
13752 max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock));
13758 intel_check_primary_plane(struct drm_plane *plane,
13759 struct intel_crtc_state *crtc_state,
13760 struct intel_plane_state *state)
13762 struct drm_crtc *crtc = state->base.crtc;
13763 struct drm_framebuffer *fb = state->base.fb;
13764 int min_scale = DRM_PLANE_HELPER_NO_SCALING;
13765 int max_scale = DRM_PLANE_HELPER_NO_SCALING;
13766 bool can_position = false;
13768 /* use scaler when colorkey is not required */
13769 if (INTEL_INFO(plane->dev)->gen >= 9 &&
13770 state->ckey.flags == I915_SET_COLORKEY_NONE) {
13772 max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state);
13773 can_position = true;
13776 return drm_plane_helper_check_update(plane, crtc, fb, &state->src,
13777 &state->dst, &state->clip,
13778 min_scale, max_scale,
13779 can_position, true,
13784 intel_commit_primary_plane(struct drm_plane *plane,
13785 struct intel_plane_state *state)
13787 struct drm_crtc *crtc = state->base.crtc;
13788 struct drm_framebuffer *fb = state->base.fb;
13789 struct drm_device *dev = plane->dev;
13790 struct drm_i915_private *dev_priv = dev->dev_private;
13791 struct intel_crtc *intel_crtc;
13792 struct drm_rect *src = &state->src;
13794 crtc = crtc ? crtc : plane->crtc;
13795 intel_crtc = to_intel_crtc(crtc);
13798 crtc->x = src->x1 >> 16;
13799 crtc->y = src->y1 >> 16;
13801 if (!crtc->state->active)
13804 if (state->visible)
13805 /* FIXME: kill this fastboot hack */
13806 intel_update_pipe_size(intel_crtc);
13808 dev_priv->display.update_primary_plane(crtc, fb, crtc->x, crtc->y);
13812 intel_disable_primary_plane(struct drm_plane *plane,
13813 struct drm_crtc *crtc)
13815 struct drm_device *dev = plane->dev;
13816 struct drm_i915_private *dev_priv = dev->dev_private;
13818 dev_priv->display.update_primary_plane(crtc, NULL, 0, 0);
13821 static void intel_begin_crtc_commit(struct drm_crtc *crtc)
13823 struct drm_device *dev = crtc->dev;
13824 struct drm_i915_private *dev_priv = dev->dev_private;
13825 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13827 if (!needs_modeset(crtc->state))
13828 intel_pre_plane_update(intel_crtc);
13830 if (intel_crtc->atomic.update_wm_pre)
13831 intel_update_watermarks(crtc);
13833 intel_runtime_pm_get(dev_priv);
13835 /* Perform vblank evasion around commit operation */
13836 if (crtc->state->active)
13837 intel_crtc->atomic.evade =
13838 intel_pipe_update_start(intel_crtc,
13839 &intel_crtc->atomic.start_vbl_count);
13841 if (!needs_modeset(crtc->state) && INTEL_INFO(dev)->gen >= 9)
13842 skl_detach_scalers(intel_crtc);
13845 static void intel_finish_crtc_commit(struct drm_crtc *crtc)
13847 struct drm_device *dev = crtc->dev;
13848 struct drm_i915_private *dev_priv = dev->dev_private;
13849 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13851 if (intel_crtc->atomic.evade)
13852 intel_pipe_update_end(intel_crtc,
13853 intel_crtc->atomic.start_vbl_count);
13855 intel_runtime_pm_put(dev_priv);
13857 intel_post_plane_update(intel_crtc);
13861 * intel_plane_destroy - destroy a plane
13862 * @plane: plane to destroy
13864 * Common destruction function for all types of planes (primary, cursor,
13867 void intel_plane_destroy(struct drm_plane *plane)
13869 struct intel_plane *intel_plane = to_intel_plane(plane);
13870 drm_plane_cleanup(plane);
13871 kfree(intel_plane);
13874 const struct drm_plane_funcs intel_plane_funcs = {
13875 .update_plane = drm_atomic_helper_update_plane,
13876 .disable_plane = drm_atomic_helper_disable_plane,
13877 .destroy = intel_plane_destroy,
13878 .set_property = drm_atomic_helper_plane_set_property,
13879 .atomic_get_property = intel_plane_atomic_get_property,
13880 .atomic_set_property = intel_plane_atomic_set_property,
13881 .atomic_duplicate_state = intel_plane_duplicate_state,
13882 .atomic_destroy_state = intel_plane_destroy_state,
13886 static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
13889 struct intel_plane *primary;
13890 struct intel_plane_state *state;
13891 const uint32_t *intel_primary_formats;
13894 primary = kzalloc(sizeof(*primary), GFP_KERNEL);
13895 if (primary == NULL)
13898 state = intel_create_plane_state(&primary->base);
13903 primary->base.state = &state->base;
13905 primary->can_scale = false;
13906 primary->max_downscale = 1;
13907 if (INTEL_INFO(dev)->gen >= 9) {
13908 primary->can_scale = true;
13909 state->scaler_id = -1;
13911 primary->pipe = pipe;
13912 primary->plane = pipe;
13913 primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe);
13914 primary->check_plane = intel_check_primary_plane;
13915 primary->commit_plane = intel_commit_primary_plane;
13916 primary->disable_plane = intel_disable_primary_plane;
13917 if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4)
13918 primary->plane = !pipe;
13920 if (INTEL_INFO(dev)->gen >= 9) {
13921 intel_primary_formats = skl_primary_formats;
13922 num_formats = ARRAY_SIZE(skl_primary_formats);
13923 } else if (INTEL_INFO(dev)->gen >= 4) {
13924 intel_primary_formats = i965_primary_formats;
13925 num_formats = ARRAY_SIZE(i965_primary_formats);
13927 intel_primary_formats = i8xx_primary_formats;
13928 num_formats = ARRAY_SIZE(i8xx_primary_formats);
13931 drm_universal_plane_init(dev, &primary->base, 0,
13932 &intel_plane_funcs,
13933 intel_primary_formats, num_formats,
13934 DRM_PLANE_TYPE_PRIMARY);
13936 if (INTEL_INFO(dev)->gen >= 4)
13937 intel_create_rotation_property(dev, primary);
13939 drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs);
13941 return &primary->base;
13944 void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane)
13946 if (!dev->mode_config.rotation_property) {
13947 unsigned long flags = BIT(DRM_ROTATE_0) |
13948 BIT(DRM_ROTATE_180);
13950 if (INTEL_INFO(dev)->gen >= 9)
13951 flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270);
13953 dev->mode_config.rotation_property =
13954 drm_mode_create_rotation_property(dev, flags);
13956 if (dev->mode_config.rotation_property)
13957 drm_object_attach_property(&plane->base.base,
13958 dev->mode_config.rotation_property,
13959 plane->base.state->rotation);
13963 intel_check_cursor_plane(struct drm_plane *plane,
13964 struct intel_crtc_state *crtc_state,
13965 struct intel_plane_state *state)
13967 struct drm_crtc *crtc = crtc_state->base.crtc;
13968 struct drm_framebuffer *fb = state->base.fb;
13969 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13973 ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src,
13974 &state->dst, &state->clip,
13975 DRM_PLANE_HELPER_NO_SCALING,
13976 DRM_PLANE_HELPER_NO_SCALING,
13977 true, true, &state->visible);
13981 /* if we want to turn off the cursor ignore width and height */
13985 /* Check for which cursor types we support */
13986 if (!cursor_size_ok(plane->dev, state->base.crtc_w, state->base.crtc_h)) {
13987 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
13988 state->base.crtc_w, state->base.crtc_h);
13992 stride = roundup_pow_of_two(state->base.crtc_w) * 4;
13993 if (obj->base.size < stride * state->base.crtc_h) {
13994 DRM_DEBUG_KMS("buffer is too small\n");
13998 if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) {
13999 DRM_DEBUG_KMS("cursor cannot be tiled\n");
14007 intel_disable_cursor_plane(struct drm_plane *plane,
14008 struct drm_crtc *crtc)
14010 intel_crtc_update_cursor(crtc, false);
14014 intel_commit_cursor_plane(struct drm_plane *plane,
14015 struct intel_plane_state *state)
14017 struct drm_crtc *crtc = state->base.crtc;
14018 struct drm_device *dev = plane->dev;
14019 struct intel_crtc *intel_crtc;
14020 struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb);
14023 crtc = crtc ? crtc : plane->crtc;
14024 intel_crtc = to_intel_crtc(crtc);
14026 plane->fb = state->base.fb;
14027 crtc->cursor_x = state->base.crtc_x;
14028 crtc->cursor_y = state->base.crtc_y;
14030 if (intel_crtc->cursor_bo == obj)
14035 else if (!INTEL_INFO(dev)->cursor_needs_physical)
14036 addr = i915_gem_obj_ggtt_offset(obj);
14038 addr = obj->phys_handle->busaddr;
14040 intel_crtc->cursor_addr = addr;
14041 intel_crtc->cursor_bo = obj;
14044 if (crtc->state->active)
14045 intel_crtc_update_cursor(crtc, state->visible);
14048 static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
14051 struct intel_plane *cursor;
14052 struct intel_plane_state *state;
14054 cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
14055 if (cursor == NULL)
14058 state = intel_create_plane_state(&cursor->base);
14063 cursor->base.state = &state->base;
14065 cursor->can_scale = false;
14066 cursor->max_downscale = 1;
14067 cursor->pipe = pipe;
14068 cursor->plane = pipe;
14069 cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe);
14070 cursor->check_plane = intel_check_cursor_plane;
14071 cursor->commit_plane = intel_commit_cursor_plane;
14072 cursor->disable_plane = intel_disable_cursor_plane;
14074 drm_universal_plane_init(dev, &cursor->base, 0,
14075 &intel_plane_funcs,
14076 intel_cursor_formats,
14077 ARRAY_SIZE(intel_cursor_formats),
14078 DRM_PLANE_TYPE_CURSOR);
14080 if (INTEL_INFO(dev)->gen >= 4) {
14081 if (!dev->mode_config.rotation_property)
14082 dev->mode_config.rotation_property =
14083 drm_mode_create_rotation_property(dev,
14084 BIT(DRM_ROTATE_0) |
14085 BIT(DRM_ROTATE_180));
14086 if (dev->mode_config.rotation_property)
14087 drm_object_attach_property(&cursor->base.base,
14088 dev->mode_config.rotation_property,
14089 state->base.rotation);
14092 if (INTEL_INFO(dev)->gen >=9)
14093 state->scaler_id = -1;
14095 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
14097 return &cursor->base;
14100 static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc,
14101 struct intel_crtc_state *crtc_state)
14104 struct intel_scaler *intel_scaler;
14105 struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state;
14107 for (i = 0; i < intel_crtc->num_scalers; i++) {
14108 intel_scaler = &scaler_state->scalers[i];
14109 intel_scaler->in_use = 0;
14110 intel_scaler->mode = PS_SCALER_MODE_DYN;
14113 scaler_state->scaler_id = -1;
14116 static void intel_crtc_init(struct drm_device *dev, int pipe)
14118 struct drm_i915_private *dev_priv = dev->dev_private;
14119 struct intel_crtc *intel_crtc;
14120 struct intel_crtc_state *crtc_state = NULL;
14121 struct drm_plane *primary = NULL;
14122 struct drm_plane *cursor = NULL;
14125 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
14126 if (intel_crtc == NULL)
14129 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
14132 intel_crtc->config = crtc_state;
14133 intel_crtc->base.state = &crtc_state->base;
14134 crtc_state->base.crtc = &intel_crtc->base;
14136 /* initialize shared scalers */
14137 if (INTEL_INFO(dev)->gen >= 9) {
14138 if (pipe == PIPE_C)
14139 intel_crtc->num_scalers = 1;
14141 intel_crtc->num_scalers = SKL_NUM_SCALERS;
14143 skl_init_scalers(dev, intel_crtc, crtc_state);
14146 primary = intel_primary_plane_create(dev, pipe);
14150 cursor = intel_cursor_plane_create(dev, pipe);
14154 ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary,
14155 cursor, &intel_crtc_funcs);
14159 drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
14160 for (i = 0; i < 256; i++) {
14161 intel_crtc->lut_r[i] = i;
14162 intel_crtc->lut_g[i] = i;
14163 intel_crtc->lut_b[i] = i;
14167 * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
14168 * is hooked to pipe B. Hence we want plane A feeding pipe B.
14170 intel_crtc->pipe = pipe;
14171 intel_crtc->plane = pipe;
14172 if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) {
14173 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
14174 intel_crtc->plane = !pipe;
14177 intel_crtc->cursor_base = ~0;
14178 intel_crtc->cursor_cntl = ~0;
14179 intel_crtc->cursor_size = ~0;
14181 intel_crtc->wm.cxsr_allowed = true;
14183 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
14184 dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
14185 dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
14186 dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
14188 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
14190 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
14195 drm_plane_cleanup(primary);
14197 drm_plane_cleanup(cursor);
14202 enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
14204 struct drm_encoder *encoder = connector->base.encoder;
14205 struct drm_device *dev = connector->base.dev;
14207 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
14209 if (!encoder || WARN_ON(!encoder->crtc))
14210 return INVALID_PIPE;
14212 return to_intel_crtc(encoder->crtc)->pipe;
14215 int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
14216 struct drm_file *file)
14218 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
14219 struct drm_crtc *drmmode_crtc;
14220 struct intel_crtc *crtc;
14222 drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id);
14224 if (!drmmode_crtc) {
14225 DRM_ERROR("no such CRTC id\n");
14229 crtc = to_intel_crtc(drmmode_crtc);
14230 pipe_from_crtc_id->pipe = crtc->pipe;
14235 static int intel_encoder_clones(struct intel_encoder *encoder)
14237 struct drm_device *dev = encoder->base.dev;
14238 struct intel_encoder *source_encoder;
14239 int index_mask = 0;
14242 for_each_intel_encoder(dev, source_encoder) {
14243 if (encoders_cloneable(encoder, source_encoder))
14244 index_mask |= (1 << entry);
14252 static bool has_edp_a(struct drm_device *dev)
14254 struct drm_i915_private *dev_priv = dev->dev_private;
14256 if (!IS_MOBILE(dev))
14259 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
14262 if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
14268 static bool intel_crt_present(struct drm_device *dev)
14270 struct drm_i915_private *dev_priv = dev->dev_private;
14272 if (INTEL_INFO(dev)->gen >= 9)
14275 if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev))
14278 if (IS_CHERRYVIEW(dev))
14281 if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support)
14287 static void intel_setup_outputs(struct drm_device *dev)
14289 struct drm_i915_private *dev_priv = dev->dev_private;
14290 struct intel_encoder *encoder;
14291 bool dpd_is_edp = false;
14293 intel_lvds_init(dev);
14295 if (intel_crt_present(dev))
14296 intel_crt_init(dev);
14298 if (IS_BROXTON(dev)) {
14300 * FIXME: Broxton doesn't support port detection via the
14301 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
14302 * detect the ports.
14304 intel_ddi_init(dev, PORT_A);
14305 intel_ddi_init(dev, PORT_B);
14306 intel_ddi_init(dev, PORT_C);
14307 } else if (HAS_DDI(dev)) {
14311 * Haswell uses DDI functions to detect digital outputs.
14312 * On SKL pre-D0 the strap isn't connected, so we assume
14315 found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
14316 /* WaIgnoreDDIAStrap: skl */
14318 (IS_SKYLAKE(dev) && INTEL_REVID(dev) < SKL_REVID_D0))
14319 intel_ddi_init(dev, PORT_A);
14321 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
14323 found = I915_READ(SFUSE_STRAP);
14325 if (found & SFUSE_STRAP_DDIB_DETECTED)
14326 intel_ddi_init(dev, PORT_B);
14327 if (found & SFUSE_STRAP_DDIC_DETECTED)
14328 intel_ddi_init(dev, PORT_C);
14329 if (found & SFUSE_STRAP_DDID_DETECTED)
14330 intel_ddi_init(dev, PORT_D);
14331 } else if (HAS_PCH_SPLIT(dev)) {
14333 dpd_is_edp = intel_dp_is_edp(dev, PORT_D);
14335 if (has_edp_a(dev))
14336 intel_dp_init(dev, DP_A, PORT_A);
14338 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
14339 /* PCH SDVOB multiplex with HDMIB */
14340 found = intel_sdvo_init(dev, PCH_SDVOB, true);
14342 intel_hdmi_init(dev, PCH_HDMIB, PORT_B);
14343 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
14344 intel_dp_init(dev, PCH_DP_B, PORT_B);
14347 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
14348 intel_hdmi_init(dev, PCH_HDMIC, PORT_C);
14350 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
14351 intel_hdmi_init(dev, PCH_HDMID, PORT_D);
14353 if (I915_READ(PCH_DP_C) & DP_DETECTED)
14354 intel_dp_init(dev, PCH_DP_C, PORT_C);
14356 if (I915_READ(PCH_DP_D) & DP_DETECTED)
14357 intel_dp_init(dev, PCH_DP_D, PORT_D);
14358 } else if (IS_VALLEYVIEW(dev)) {
14360 * The DP_DETECTED bit is the latched state of the DDC
14361 * SDA pin at boot. However since eDP doesn't require DDC
14362 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14363 * eDP ports may have been muxed to an alternate function.
14364 * Thus we can't rely on the DP_DETECTED bit alone to detect
14365 * eDP ports. Consult the VBT as well as DP_DETECTED to
14366 * detect eDP ports.
14368 if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED &&
14369 !intel_dp_is_edp(dev, PORT_B))
14370 intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB,
14372 if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED ||
14373 intel_dp_is_edp(dev, PORT_B))
14374 intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
14376 if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED &&
14377 !intel_dp_is_edp(dev, PORT_C))
14378 intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC,
14380 if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED ||
14381 intel_dp_is_edp(dev, PORT_C))
14382 intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
14384 if (IS_CHERRYVIEW(dev)) {
14385 if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED)
14386 intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID,
14388 /* eDP not supported on port D, so don't check VBT */
14389 if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED)
14390 intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D);
14393 intel_dsi_init(dev);
14394 } else if (!IS_GEN2(dev) && !IS_PINEVIEW(dev)) {
14395 bool found = false;
14397 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14398 DRM_DEBUG_KMS("probing SDVOB\n");
14399 found = intel_sdvo_init(dev, GEN3_SDVOB, true);
14400 if (!found && IS_G4X(dev)) {
14401 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
14402 intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
14405 if (!found && IS_G4X(dev))
14406 intel_dp_init(dev, DP_B, PORT_B);
14409 /* Before G4X SDVOC doesn't have its own detect register */
14411 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14412 DRM_DEBUG_KMS("probing SDVOC\n");
14413 found = intel_sdvo_init(dev, GEN3_SDVOC, false);
14416 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
14419 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
14420 intel_hdmi_init(dev, GEN4_HDMIC, PORT_C);
14423 intel_dp_init(dev, DP_C, PORT_C);
14427 (I915_READ(DP_D) & DP_DETECTED))
14428 intel_dp_init(dev, DP_D, PORT_D);
14429 } else if (IS_GEN2(dev))
14430 intel_dvo_init(dev);
14432 if (SUPPORTS_TV(dev))
14433 intel_tv_init(dev);
14435 intel_psr_init(dev);
14437 for_each_intel_encoder(dev, encoder) {
14438 encoder->base.possible_crtcs = encoder->crtc_mask;
14439 encoder->base.possible_clones =
14440 intel_encoder_clones(encoder);
14443 intel_init_pch_refclk(dev);
14445 drm_helper_move_panel_connectors_to_head(dev);
14448 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
14450 struct drm_device *dev = fb->dev;
14451 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
14453 drm_framebuffer_cleanup(fb);
14454 mutex_lock(&dev->struct_mutex);
14455 WARN_ON(!intel_fb->obj->framebuffer_references--);
14456 drm_gem_object_unreference(&intel_fb->obj->base);
14457 mutex_unlock(&dev->struct_mutex);
14461 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
14462 struct drm_file *file,
14463 unsigned int *handle)
14465 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
14466 struct drm_i915_gem_object *obj = intel_fb->obj;
14468 return drm_gem_handle_create(file, &obj->base, handle);
14471 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
14472 struct drm_file *file,
14473 unsigned flags, unsigned color,
14474 struct drm_clip_rect *clips,
14475 unsigned num_clips)
14477 struct drm_device *dev = fb->dev;
14478 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
14479 struct drm_i915_gem_object *obj = intel_fb->obj;
14481 mutex_lock(&dev->struct_mutex);
14482 intel_fb_obj_flush(obj, false, ORIGIN_GTT);
14483 mutex_unlock(&dev->struct_mutex);
14488 static const struct drm_framebuffer_funcs intel_fb_funcs = {
14489 .destroy = intel_user_framebuffer_destroy,
14490 .create_handle = intel_user_framebuffer_create_handle,
14491 .dirty = intel_user_framebuffer_dirty,
14495 u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier,
14496 uint32_t pixel_format)
14498 u32 gen = INTEL_INFO(dev)->gen;
14501 /* "The stride in bytes must not exceed the of the size of 8K
14502 * pixels and 32K bytes."
14504 return min(8192*drm_format_plane_cpp(pixel_format, 0), 32768);
14505 } else if (gen >= 5 && !IS_VALLEYVIEW(dev)) {
14507 } else if (gen >= 4) {
14508 if (fb_modifier == I915_FORMAT_MOD_X_TILED)
14512 } else if (gen >= 3) {
14513 if (fb_modifier == I915_FORMAT_MOD_X_TILED)
14518 /* XXX DSPC is limited to 4k tiled */
14523 static int intel_framebuffer_init(struct drm_device *dev,
14524 struct intel_framebuffer *intel_fb,
14525 struct drm_mode_fb_cmd2 *mode_cmd,
14526 struct drm_i915_gem_object *obj)
14528 unsigned int aligned_height;
14530 u32 pitch_limit, stride_alignment;
14532 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
14534 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
14535 /* Enforce that fb modifier and tiling mode match, but only for
14536 * X-tiled. This is needed for FBC. */
14537 if (!!(obj->tiling_mode == I915_TILING_X) !=
14538 !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) {
14539 DRM_DEBUG("tiling_mode doesn't match fb modifier\n");
14543 if (obj->tiling_mode == I915_TILING_X)
14544 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
14545 else if (obj->tiling_mode == I915_TILING_Y) {
14546 DRM_DEBUG("No Y tiling for legacy addfb\n");
14551 /* Passed in modifier sanity checking. */
14552 switch (mode_cmd->modifier[0]) {
14553 case I915_FORMAT_MOD_Y_TILED:
14554 case I915_FORMAT_MOD_Yf_TILED:
14555 if (INTEL_INFO(dev)->gen < 9) {
14556 DRM_DEBUG("Unsupported tiling 0x%llx!\n",
14557 mode_cmd->modifier[0]);
14560 case DRM_FORMAT_MOD_NONE:
14561 case I915_FORMAT_MOD_X_TILED:
14564 DRM_DEBUG("Unsupported fb modifier 0x%llx!\n",
14565 mode_cmd->modifier[0]);
14569 stride_alignment = intel_fb_stride_alignment(dev, mode_cmd->modifier[0],
14570 mode_cmd->pixel_format);
14571 if (mode_cmd->pitches[0] & (stride_alignment - 1)) {
14572 DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n",
14573 mode_cmd->pitches[0], stride_alignment);
14577 pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0],
14578 mode_cmd->pixel_format);
14579 if (mode_cmd->pitches[0] > pitch_limit) {
14580 DRM_DEBUG("%s pitch (%u) must be at less than %d\n",
14581 mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ?
14582 "tiled" : "linear",
14583 mode_cmd->pitches[0], pitch_limit);
14587 if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED &&
14588 mode_cmd->pitches[0] != obj->stride) {
14589 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
14590 mode_cmd->pitches[0], obj->stride);
14594 /* Reject formats not supported by any plane early. */
14595 switch (mode_cmd->pixel_format) {
14596 case DRM_FORMAT_C8:
14597 case DRM_FORMAT_RGB565:
14598 case DRM_FORMAT_XRGB8888:
14599 case DRM_FORMAT_ARGB8888:
14601 case DRM_FORMAT_XRGB1555:
14602 if (INTEL_INFO(dev)->gen > 3) {
14603 DRM_DEBUG("unsupported pixel format: %s\n",
14604 drm_get_format_name(mode_cmd->pixel_format));
14608 case DRM_FORMAT_ABGR8888:
14609 if (!IS_VALLEYVIEW(dev) && INTEL_INFO(dev)->gen < 9) {
14610 DRM_DEBUG("unsupported pixel format: %s\n",
14611 drm_get_format_name(mode_cmd->pixel_format));
14615 case DRM_FORMAT_XBGR8888:
14616 case DRM_FORMAT_XRGB2101010:
14617 case DRM_FORMAT_XBGR2101010:
14618 if (INTEL_INFO(dev)->gen < 4) {
14619 DRM_DEBUG("unsupported pixel format: %s\n",
14620 drm_get_format_name(mode_cmd->pixel_format));
14624 case DRM_FORMAT_ABGR2101010:
14625 if (!IS_VALLEYVIEW(dev)) {
14626 DRM_DEBUG("unsupported pixel format: %s\n",
14627 drm_get_format_name(mode_cmd->pixel_format));
14631 case DRM_FORMAT_YUYV:
14632 case DRM_FORMAT_UYVY:
14633 case DRM_FORMAT_YVYU:
14634 case DRM_FORMAT_VYUY:
14635 if (INTEL_INFO(dev)->gen < 5) {
14636 DRM_DEBUG("unsupported pixel format: %s\n",
14637 drm_get_format_name(mode_cmd->pixel_format));
14642 DRM_DEBUG("unsupported pixel format: %s\n",
14643 drm_get_format_name(mode_cmd->pixel_format));
14647 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14648 if (mode_cmd->offsets[0] != 0)
14651 aligned_height = intel_fb_align_height(dev, mode_cmd->height,
14652 mode_cmd->pixel_format,
14653 mode_cmd->modifier[0]);
14654 /* FIXME drm helper for size checks (especially planar formats)? */
14655 if (obj->base.size < aligned_height * mode_cmd->pitches[0])
14658 drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
14659 intel_fb->obj = obj;
14660 intel_fb->obj->framebuffer_references++;
14662 ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
14664 DRM_ERROR("framebuffer init failed %d\n", ret);
14671 static struct drm_framebuffer *
14672 intel_user_framebuffer_create(struct drm_device *dev,
14673 struct drm_file *filp,
14674 struct drm_mode_fb_cmd2 *mode_cmd)
14676 struct drm_i915_gem_object *obj;
14678 obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
14679 mode_cmd->handles[0]));
14680 if (&obj->base == NULL)
14681 return ERR_PTR(-ENOENT);
14683 return intel_framebuffer_create(dev, mode_cmd, obj);
14686 #ifndef CONFIG_DRM_I915_FBDEV
14687 static inline void intel_fbdev_output_poll_changed(struct drm_device *dev)
14692 static const struct drm_mode_config_funcs intel_mode_funcs = {
14693 .fb_create = intel_user_framebuffer_create,
14694 .output_poll_changed = intel_fbdev_output_poll_changed,
14695 .atomic_check = intel_atomic_check,
14696 .atomic_commit = intel_atomic_commit,
14697 .atomic_state_alloc = intel_atomic_state_alloc,
14698 .atomic_state_clear = intel_atomic_state_clear,
14701 /* Set up chip specific display functions */
14702 static void intel_init_display(struct drm_device *dev)
14704 struct drm_i915_private *dev_priv = dev->dev_private;
14706 if (HAS_PCH_SPLIT(dev) || IS_G4X(dev))
14707 dev_priv->display.find_dpll = g4x_find_best_dpll;
14708 else if (IS_CHERRYVIEW(dev))
14709 dev_priv->display.find_dpll = chv_find_best_dpll;
14710 else if (IS_VALLEYVIEW(dev))
14711 dev_priv->display.find_dpll = vlv_find_best_dpll;
14712 else if (IS_PINEVIEW(dev))
14713 dev_priv->display.find_dpll = pnv_find_best_dpll;
14715 dev_priv->display.find_dpll = i9xx_find_best_dpll;
14717 if (INTEL_INFO(dev)->gen >= 9) {
14718 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14719 dev_priv->display.get_initial_plane_config =
14720 skylake_get_initial_plane_config;
14721 dev_priv->display.crtc_compute_clock =
14722 haswell_crtc_compute_clock;
14723 dev_priv->display.crtc_enable = haswell_crtc_enable;
14724 dev_priv->display.crtc_disable = haswell_crtc_disable;
14725 dev_priv->display.update_primary_plane =
14726 skylake_update_primary_plane;
14727 } else if (HAS_DDI(dev)) {
14728 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14729 dev_priv->display.get_initial_plane_config =
14730 ironlake_get_initial_plane_config;
14731 dev_priv->display.crtc_compute_clock =
14732 haswell_crtc_compute_clock;
14733 dev_priv->display.crtc_enable = haswell_crtc_enable;
14734 dev_priv->display.crtc_disable = haswell_crtc_disable;
14735 dev_priv->display.update_primary_plane =
14736 ironlake_update_primary_plane;
14737 } else if (HAS_PCH_SPLIT(dev)) {
14738 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
14739 dev_priv->display.get_initial_plane_config =
14740 ironlake_get_initial_plane_config;
14741 dev_priv->display.crtc_compute_clock =
14742 ironlake_crtc_compute_clock;
14743 dev_priv->display.crtc_enable = ironlake_crtc_enable;
14744 dev_priv->display.crtc_disable = ironlake_crtc_disable;
14745 dev_priv->display.update_primary_plane =
14746 ironlake_update_primary_plane;
14747 } else if (IS_VALLEYVIEW(dev)) {
14748 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14749 dev_priv->display.get_initial_plane_config =
14750 i9xx_get_initial_plane_config;
14751 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
14752 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14753 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14754 dev_priv->display.update_primary_plane =
14755 i9xx_update_primary_plane;
14757 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14758 dev_priv->display.get_initial_plane_config =
14759 i9xx_get_initial_plane_config;
14760 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
14761 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14762 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14763 dev_priv->display.update_primary_plane =
14764 i9xx_update_primary_plane;
14767 /* Returns the core display clock speed */
14768 if (IS_SKYLAKE(dev))
14769 dev_priv->display.get_display_clock_speed =
14770 skylake_get_display_clock_speed;
14771 else if (IS_BROXTON(dev))
14772 dev_priv->display.get_display_clock_speed =
14773 broxton_get_display_clock_speed;
14774 else if (IS_BROADWELL(dev))
14775 dev_priv->display.get_display_clock_speed =
14776 broadwell_get_display_clock_speed;
14777 else if (IS_HASWELL(dev))
14778 dev_priv->display.get_display_clock_speed =
14779 haswell_get_display_clock_speed;
14780 else if (IS_VALLEYVIEW(dev))
14781 dev_priv->display.get_display_clock_speed =
14782 valleyview_get_display_clock_speed;
14783 else if (IS_GEN5(dev))
14784 dev_priv->display.get_display_clock_speed =
14785 ilk_get_display_clock_speed;
14786 else if (IS_I945G(dev) || IS_BROADWATER(dev) ||
14787 IS_GEN6(dev) || IS_IVYBRIDGE(dev))
14788 dev_priv->display.get_display_clock_speed =
14789 i945_get_display_clock_speed;
14790 else if (IS_GM45(dev))
14791 dev_priv->display.get_display_clock_speed =
14792 gm45_get_display_clock_speed;
14793 else if (IS_CRESTLINE(dev))
14794 dev_priv->display.get_display_clock_speed =
14795 i965gm_get_display_clock_speed;
14796 else if (IS_PINEVIEW(dev))
14797 dev_priv->display.get_display_clock_speed =
14798 pnv_get_display_clock_speed;
14799 else if (IS_G33(dev) || IS_G4X(dev))
14800 dev_priv->display.get_display_clock_speed =
14801 g33_get_display_clock_speed;
14802 else if (IS_I915G(dev))
14803 dev_priv->display.get_display_clock_speed =
14804 i915_get_display_clock_speed;
14805 else if (IS_I945GM(dev) || IS_845G(dev))
14806 dev_priv->display.get_display_clock_speed =
14807 i9xx_misc_get_display_clock_speed;
14808 else if (IS_PINEVIEW(dev))
14809 dev_priv->display.get_display_clock_speed =
14810 pnv_get_display_clock_speed;
14811 else if (IS_I915GM(dev))
14812 dev_priv->display.get_display_clock_speed =
14813 i915gm_get_display_clock_speed;
14814 else if (IS_I865G(dev))
14815 dev_priv->display.get_display_clock_speed =
14816 i865_get_display_clock_speed;
14817 else if (IS_I85X(dev))
14818 dev_priv->display.get_display_clock_speed =
14819 i85x_get_display_clock_speed;
14821 WARN(!IS_I830(dev), "Unknown platform. Assuming 133 MHz CDCLK\n");
14822 dev_priv->display.get_display_clock_speed =
14823 i830_get_display_clock_speed;
14826 if (IS_GEN5(dev)) {
14827 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
14828 } else if (IS_GEN6(dev)) {
14829 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
14830 } else if (IS_IVYBRIDGE(dev)) {
14831 /* FIXME: detect B0+ stepping and use auto training */
14832 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
14833 } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
14834 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
14835 if (IS_BROADWELL(dev)) {
14836 dev_priv->display.modeset_commit_cdclk =
14837 broadwell_modeset_commit_cdclk;
14838 dev_priv->display.modeset_calc_cdclk =
14839 broadwell_modeset_calc_cdclk;
14841 } else if (IS_VALLEYVIEW(dev)) {
14842 dev_priv->display.modeset_commit_cdclk =
14843 valleyview_modeset_commit_cdclk;
14844 dev_priv->display.modeset_calc_cdclk =
14845 valleyview_modeset_calc_cdclk;
14846 } else if (IS_BROXTON(dev)) {
14847 dev_priv->display.modeset_commit_cdclk =
14848 broxton_modeset_commit_cdclk;
14849 dev_priv->display.modeset_calc_cdclk =
14850 broxton_modeset_calc_cdclk;
14853 switch (INTEL_INFO(dev)->gen) {
14855 dev_priv->display.queue_flip = intel_gen2_queue_flip;
14859 dev_priv->display.queue_flip = intel_gen3_queue_flip;
14864 dev_priv->display.queue_flip = intel_gen4_queue_flip;
14868 dev_priv->display.queue_flip = intel_gen6_queue_flip;
14871 case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
14872 dev_priv->display.queue_flip = intel_gen7_queue_flip;
14875 /* Drop through - unsupported since execlist only. */
14877 /* Default just returns -ENODEV to indicate unsupported */
14878 dev_priv->display.queue_flip = intel_default_queue_flip;
14881 intel_panel_init_backlight_funcs(dev);
14883 mutex_init(&dev_priv->pps_mutex);
14887 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
14888 * resume, or other times. This quirk makes sure that's the case for
14889 * affected systems.
14891 static void quirk_pipea_force(struct drm_device *dev)
14893 struct drm_i915_private *dev_priv = dev->dev_private;
14895 dev_priv->quirks |= QUIRK_PIPEA_FORCE;
14896 DRM_INFO("applying pipe a force quirk\n");
14899 static void quirk_pipeb_force(struct drm_device *dev)
14901 struct drm_i915_private *dev_priv = dev->dev_private;
14903 dev_priv->quirks |= QUIRK_PIPEB_FORCE;
14904 DRM_INFO("applying pipe b force quirk\n");
14908 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
14910 static void quirk_ssc_force_disable(struct drm_device *dev)
14912 struct drm_i915_private *dev_priv = dev->dev_private;
14913 dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
14914 DRM_INFO("applying lvds SSC disable quirk\n");
14918 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
14921 static void quirk_invert_brightness(struct drm_device *dev)
14923 struct drm_i915_private *dev_priv = dev->dev_private;
14924 dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
14925 DRM_INFO("applying inverted panel brightness quirk\n");
14928 /* Some VBT's incorrectly indicate no backlight is present */
14929 static void quirk_backlight_present(struct drm_device *dev)
14931 struct drm_i915_private *dev_priv = dev->dev_private;
14932 dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT;
14933 DRM_INFO("applying backlight present quirk\n");
14936 struct intel_quirk {
14938 int subsystem_vendor;
14939 int subsystem_device;
14940 void (*hook)(struct drm_device *dev);
14943 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
14944 struct intel_dmi_quirk {
14945 void (*hook)(struct drm_device *dev);
14946 const struct dmi_system_id (*dmi_id_list)[];
14949 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
14951 DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
14955 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
14957 .dmi_id_list = &(const struct dmi_system_id[]) {
14959 .callback = intel_dmi_reverse_brightness,
14960 .ident = "NCR Corporation",
14961 .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
14962 DMI_MATCH(DMI_PRODUCT_NAME, ""),
14965 { } /* terminating entry */
14967 .hook = quirk_invert_brightness,
14971 static struct intel_quirk intel_quirks[] = {
14972 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
14973 { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
14975 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
14976 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
14978 /* 830 needs to leave pipe A & dpll A up */
14979 { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
14981 /* 830 needs to leave pipe B & dpll B up */
14982 { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force },
14984 /* Lenovo U160 cannot use SSC on LVDS */
14985 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
14987 /* Sony Vaio Y cannot use SSC on LVDS */
14988 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
14990 /* Acer Aspire 5734Z must invert backlight brightness */
14991 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
14993 /* Acer/eMachines G725 */
14994 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
14996 /* Acer/eMachines e725 */
14997 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
14999 /* Acer/Packard Bell NCL20 */
15000 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
15002 /* Acer Aspire 4736Z */
15003 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
15005 /* Acer Aspire 5336 */
15006 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
15008 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
15009 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present },
15011 /* Acer C720 Chromebook (Core i3 4005U) */
15012 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present },
15014 /* Apple Macbook 2,1 (Core 2 T7400) */
15015 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present },
15017 /* Toshiba CB35 Chromebook (Celeron 2955U) */
15018 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present },
15020 /* HP Chromebook 14 (Celeron 2955U) */
15021 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present },
15023 /* Dell Chromebook 11 */
15024 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present },
15027 static void intel_init_quirks(struct drm_device *dev)
15029 struct pci_dev *d = dev->pdev;
15032 for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
15033 struct intel_quirk *q = &intel_quirks[i];
15035 if (d->device == q->device &&
15036 (d->subsystem_vendor == q->subsystem_vendor ||
15037 q->subsystem_vendor == PCI_ANY_ID) &&
15038 (d->subsystem_device == q->subsystem_device ||
15039 q->subsystem_device == PCI_ANY_ID))
15042 for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
15043 if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
15044 intel_dmi_quirks[i].hook(dev);
15048 /* Disable the VGA plane that we never use */
15049 static void i915_disable_vga(struct drm_device *dev)
15051 struct drm_i915_private *dev_priv = dev->dev_private;
15053 u32 vga_reg = i915_vgacntrl_reg(dev);
15055 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
15056 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
15057 outb(SR01, VGA_SR_INDEX);
15058 sr1 = inb(VGA_SR_DATA);
15059 outb(sr1 | 1<<5, VGA_SR_DATA);
15060 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
15063 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
15064 POSTING_READ(vga_reg);
15067 void intel_modeset_init_hw(struct drm_device *dev)
15069 intel_update_cdclk(dev);
15070 intel_prepare_ddi(dev);
15071 intel_init_clock_gating(dev);
15072 intel_enable_gt_powersave(dev);
15075 void intel_modeset_init(struct drm_device *dev)
15077 struct drm_i915_private *dev_priv = dev->dev_private;
15080 struct intel_crtc *crtc;
15082 drm_mode_config_init(dev);
15084 dev->mode_config.min_width = 0;
15085 dev->mode_config.min_height = 0;
15087 dev->mode_config.preferred_depth = 24;
15088 dev->mode_config.prefer_shadow = 1;
15090 dev->mode_config.allow_fb_modifiers = true;
15092 dev->mode_config.funcs = &intel_mode_funcs;
15094 intel_init_quirks(dev);
15096 intel_init_pm(dev);
15098 if (INTEL_INFO(dev)->num_pipes == 0)
15101 intel_init_display(dev);
15102 intel_init_audio(dev);
15104 if (IS_GEN2(dev)) {
15105 dev->mode_config.max_width = 2048;
15106 dev->mode_config.max_height = 2048;
15107 } else if (IS_GEN3(dev)) {
15108 dev->mode_config.max_width = 4096;
15109 dev->mode_config.max_height = 4096;
15111 dev->mode_config.max_width = 8192;
15112 dev->mode_config.max_height = 8192;
15115 if (IS_845G(dev) || IS_I865G(dev)) {
15116 dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512;
15117 dev->mode_config.cursor_height = 1023;
15118 } else if (IS_GEN2(dev)) {
15119 dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
15120 dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
15122 dev->mode_config.cursor_width = MAX_CURSOR_WIDTH;
15123 dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT;
15126 dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
15128 DRM_DEBUG_KMS("%d display pipe%s available.\n",
15129 INTEL_INFO(dev)->num_pipes,
15130 INTEL_INFO(dev)->num_pipes > 1 ? "s" : "");
15132 for_each_pipe(dev_priv, pipe) {
15133 intel_crtc_init(dev, pipe);
15134 for_each_sprite(dev_priv, pipe, sprite) {
15135 ret = intel_plane_init(dev, pipe, sprite);
15137 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
15138 pipe_name(pipe), sprite_name(pipe, sprite), ret);
15142 intel_init_dpio(dev);
15144 intel_shared_dpll_init(dev);
15146 /* Just disable it once at startup */
15147 i915_disable_vga(dev);
15148 intel_setup_outputs(dev);
15150 /* Just in case the BIOS is doing something questionable. */
15151 intel_fbc_disable(dev_priv);
15153 drm_modeset_lock_all(dev);
15154 intel_modeset_setup_hw_state(dev);
15155 drm_modeset_unlock_all(dev);
15157 for_each_intel_crtc(dev, crtc) {
15158 struct intel_initial_plane_config plane_config = {};
15164 * Note that reserving the BIOS fb up front prevents us
15165 * from stuffing other stolen allocations like the ring
15166 * on top. This prevents some ugliness at boot time, and
15167 * can even allow for smooth boot transitions if the BIOS
15168 * fb is large enough for the active pipe configuration.
15170 dev_priv->display.get_initial_plane_config(crtc,
15174 * If the fb is shared between multiple heads, we'll
15175 * just get the first one.
15177 intel_find_initial_plane_obj(crtc, &plane_config);
15181 static void intel_enable_pipe_a(struct drm_device *dev)
15183 struct intel_connector *connector;
15184 struct drm_connector *crt = NULL;
15185 struct intel_load_detect_pipe load_detect_temp;
15186 struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx;
15188 /* We can't just switch on the pipe A, we need to set things up with a
15189 * proper mode and output configuration. As a gross hack, enable pipe A
15190 * by enabling the load detect pipe once. */
15191 for_each_intel_connector(dev, connector) {
15192 if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
15193 crt = &connector->base;
15201 if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx))
15202 intel_release_load_detect_pipe(crt, &load_detect_temp, ctx);
15206 intel_check_plane_mapping(struct intel_crtc *crtc)
15208 struct drm_device *dev = crtc->base.dev;
15209 struct drm_i915_private *dev_priv = dev->dev_private;
15212 if (INTEL_INFO(dev)->num_pipes == 1)
15215 reg = DSPCNTR(!crtc->plane);
15216 val = I915_READ(reg);
15218 if ((val & DISPLAY_PLANE_ENABLE) &&
15219 (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
15225 static void intel_sanitize_crtc(struct intel_crtc *crtc)
15227 struct drm_device *dev = crtc->base.dev;
15228 struct drm_i915_private *dev_priv = dev->dev_private;
15229 struct intel_encoder *encoder;
15233 /* Clear any frame start delays used for debugging left by the BIOS */
15234 reg = PIPECONF(crtc->config->cpu_transcoder);
15235 I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
15237 /* restore vblank interrupts to correct state */
15238 drm_crtc_vblank_reset(&crtc->base);
15239 if (crtc->active) {
15240 drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode);
15241 update_scanline_offset(crtc);
15242 drm_crtc_vblank_on(&crtc->base);
15245 /* We need to sanitize the plane -> pipe mapping first because this will
15246 * disable the crtc (and hence change the state) if it is wrong. Note
15247 * that gen4+ has a fixed plane -> pipe mapping. */
15248 if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
15251 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
15252 crtc->base.base.id);
15254 /* Pipe has the wrong plane attached and the plane is active.
15255 * Temporarily change the plane mapping and disable everything
15257 plane = crtc->plane;
15258 to_intel_plane_state(crtc->base.primary->state)->visible = true;
15259 crtc->plane = !plane;
15260 intel_crtc_disable_noatomic(&crtc->base);
15261 crtc->plane = plane;
15264 if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
15265 crtc->pipe == PIPE_A && !crtc->active) {
15266 /* BIOS forgot to enable pipe A, this mostly happens after
15267 * resume. Force-enable the pipe to fix this, the update_dpms
15268 * call below we restore the pipe to the right state, but leave
15269 * the required bits on. */
15270 intel_enable_pipe_a(dev);
15273 /* Adjust the state of the output pipe according to whether we
15274 * have active connectors/encoders. */
15276 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
15277 enable |= encoder->connectors_active;
15280 intel_crtc_disable_noatomic(&crtc->base);
15282 if (crtc->active != crtc->base.state->active) {
15284 /* This can happen either due to bugs in the get_hw_state
15285 * functions or because of calls to intel_crtc_disable_noatomic,
15286 * or because the pipe is force-enabled due to the
15288 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
15289 crtc->base.base.id,
15290 crtc->base.state->enable ? "enabled" : "disabled",
15291 crtc->active ? "enabled" : "disabled");
15293 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, NULL) < 0);
15294 crtc->base.state->active = crtc->active;
15295 crtc->base.enabled = crtc->active;
15297 /* Because we only establish the connector -> encoder ->
15298 * crtc links if something is active, this means the
15299 * crtc is now deactivated. Break the links. connector
15300 * -> encoder links are only establish when things are
15301 * actually up, hence no need to break them. */
15302 WARN_ON(crtc->active);
15304 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
15305 WARN_ON(encoder->connectors_active);
15306 encoder->base.crtc = NULL;
15310 if (crtc->active || HAS_GMCH_DISPLAY(dev)) {
15312 * We start out with underrun reporting disabled to avoid races.
15313 * For correct bookkeeping mark this on active crtcs.
15315 * Also on gmch platforms we dont have any hardware bits to
15316 * disable the underrun reporting. Which means we need to start
15317 * out with underrun reporting disabled also on inactive pipes,
15318 * since otherwise we'll complain about the garbage we read when
15319 * e.g. coming up after runtime pm.
15321 * No protection against concurrent access is required - at
15322 * worst a fifo underrun happens which also sets this to false.
15324 crtc->cpu_fifo_underrun_disabled = true;
15325 crtc->pch_fifo_underrun_disabled = true;
15329 static void intel_sanitize_encoder(struct intel_encoder *encoder)
15331 struct intel_connector *connector;
15332 struct drm_device *dev = encoder->base.dev;
15334 /* We need to check both for a crtc link (meaning that the
15335 * encoder is active and trying to read from a pipe) and the
15336 * pipe itself being active. */
15337 bool has_active_crtc = encoder->base.crtc &&
15338 to_intel_crtc(encoder->base.crtc)->active;
15340 if (encoder->connectors_active && !has_active_crtc) {
15341 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15342 encoder->base.base.id,
15343 encoder->base.name);
15345 /* Connector is active, but has no active pipe. This is
15346 * fallout from our resume register restoring. Disable
15347 * the encoder manually again. */
15348 if (encoder->base.crtc) {
15349 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15350 encoder->base.base.id,
15351 encoder->base.name);
15352 encoder->disable(encoder);
15353 if (encoder->post_disable)
15354 encoder->post_disable(encoder);
15356 encoder->base.crtc = NULL;
15357 encoder->connectors_active = false;
15359 /* Inconsistent output/port/pipe state happens presumably due to
15360 * a bug in one of the get_hw_state functions. Or someplace else
15361 * in our code, like the register restore mess on resume. Clamp
15362 * things to off as a safer default. */
15363 for_each_intel_connector(dev, connector) {
15364 if (connector->encoder != encoder)
15366 connector->base.dpms = DRM_MODE_DPMS_OFF;
15367 connector->base.encoder = NULL;
15370 /* Enabled encoders without active connectors will be fixed in
15371 * the crtc fixup. */
15374 void i915_redisable_vga_power_on(struct drm_device *dev)
15376 struct drm_i915_private *dev_priv = dev->dev_private;
15377 u32 vga_reg = i915_vgacntrl_reg(dev);
15379 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
15380 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
15381 i915_disable_vga(dev);
15385 void i915_redisable_vga(struct drm_device *dev)
15387 struct drm_i915_private *dev_priv = dev->dev_private;
15389 /* This function can be called both from intel_modeset_setup_hw_state or
15390 * at a very early point in our resume sequence, where the power well
15391 * structures are not yet restored. Since this function is at a very
15392 * paranoid "someone might have enabled VGA while we were not looking"
15393 * level, just check if the power well is enabled instead of trying to
15394 * follow the "don't touch the power well if we don't need it" policy
15395 * the rest of the driver uses. */
15396 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_VGA))
15399 i915_redisable_vga_power_on(dev);
15402 static bool primary_get_hw_state(struct intel_crtc *crtc)
15404 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
15406 return !!(I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE);
15409 static void readout_plane_state(struct intel_crtc *crtc,
15410 struct intel_crtc_state *crtc_state)
15412 struct intel_plane *p;
15413 struct intel_plane_state *plane_state;
15414 bool active = crtc_state->base.active;
15416 for_each_intel_plane(crtc->base.dev, p) {
15417 if (crtc->pipe != p->pipe)
15420 plane_state = to_intel_plane_state(p->base.state);
15422 if (p->base.type == DRM_PLANE_TYPE_PRIMARY)
15423 plane_state->visible = primary_get_hw_state(crtc);
15426 p->disable_plane(&p->base, &crtc->base);
15428 plane_state->visible = false;
15433 static void intel_modeset_readout_hw_state(struct drm_device *dev)
15435 struct drm_i915_private *dev_priv = dev->dev_private;
15437 struct intel_crtc *crtc;
15438 struct intel_encoder *encoder;
15439 struct intel_connector *connector;
15442 for_each_intel_crtc(dev, crtc) {
15443 __drm_atomic_helper_crtc_destroy_state(&crtc->base, crtc->base.state);
15444 memset(crtc->config, 0, sizeof(*crtc->config));
15445 crtc->config->base.crtc = &crtc->base;
15447 crtc->config->quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE;
15449 crtc->active = dev_priv->display.get_pipe_config(crtc,
15452 crtc->base.state->active = crtc->active;
15453 crtc->base.enabled = crtc->active;
15455 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
15456 if (crtc->base.state->active) {
15457 intel_mode_from_pipe_config(&crtc->base.mode, crtc->config);
15458 intel_mode_from_pipe_config(&crtc->base.state->adjusted_mode, crtc->config);
15459 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
15462 * The initial mode needs to be set in order to keep
15463 * the atomic core happy. It wants a valid mode if the
15464 * crtc's enabled, so we do the above call.
15466 * At this point some state updated by the connectors
15467 * in their ->detect() callback has not run yet, so
15468 * no recalculation can be done yet.
15470 * Even if we could do a recalculation and modeset
15471 * right now it would cause a double modeset if
15472 * fbdev or userspace chooses a different initial mode.
15474 * So to prevent the double modeset, fail the memcmp
15475 * test in drm_atomic_set_mode_for_crtc to get a new
15476 * mode blob, and compare if the mode blob changed
15477 * when the PIPE_CONFIG_QUIRK_INHERITED_MODE quirk is
15480 * If that happens, someone indicated they wanted a
15481 * mode change, which means it's safe to do a full
15484 crtc->base.state->mode.private_flags = ~0;
15487 crtc->base.hwmode = crtc->config->base.adjusted_mode;
15488 readout_plane_state(crtc, to_intel_crtc_state(crtc->base.state));
15490 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
15491 crtc->base.base.id,
15492 crtc->active ? "enabled" : "disabled");
15495 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15496 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15498 pll->on = pll->get_hw_state(dev_priv, pll,
15499 &pll->config.hw_state);
15501 pll->config.crtc_mask = 0;
15502 for_each_intel_crtc(dev, crtc) {
15503 if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) {
15505 pll->config.crtc_mask |= 1 << crtc->pipe;
15509 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
15510 pll->name, pll->config.crtc_mask, pll->on);
15512 if (pll->config.crtc_mask)
15513 intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
15516 for_each_intel_encoder(dev, encoder) {
15519 if (encoder->get_hw_state(encoder, &pipe)) {
15520 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
15521 encoder->base.crtc = &crtc->base;
15522 encoder->get_config(encoder, crtc->config);
15524 encoder->base.crtc = NULL;
15527 encoder->connectors_active = false;
15528 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15529 encoder->base.base.id,
15530 encoder->base.name,
15531 encoder->base.crtc ? "enabled" : "disabled",
15535 for_each_intel_connector(dev, connector) {
15536 if (connector->get_hw_state(connector)) {
15537 connector->base.dpms = DRM_MODE_DPMS_ON;
15538 connector->encoder->connectors_active = true;
15539 connector->base.encoder = &connector->encoder->base;
15541 connector->base.dpms = DRM_MODE_DPMS_OFF;
15542 connector->base.encoder = NULL;
15544 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
15545 connector->base.base.id,
15546 connector->base.name,
15547 connector->base.encoder ? "enabled" : "disabled");
15551 /* Scan out the current hw modeset state,
15552 * and sanitizes it to the current state
15555 intel_modeset_setup_hw_state(struct drm_device *dev)
15557 struct drm_i915_private *dev_priv = dev->dev_private;
15559 struct intel_crtc *crtc;
15560 struct intel_encoder *encoder;
15563 intel_modeset_readout_hw_state(dev);
15565 /* HW state is read out, now we need to sanitize this mess. */
15566 for_each_intel_encoder(dev, encoder) {
15567 intel_sanitize_encoder(encoder);
15570 for_each_pipe(dev_priv, pipe) {
15571 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
15572 intel_sanitize_crtc(crtc);
15573 intel_dump_pipe_config(crtc, crtc->config,
15574 "[setup_hw_state]");
15577 intel_modeset_update_connector_atomic_state(dev);
15579 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15580 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15582 if (!pll->on || pll->active)
15585 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name);
15587 pll->disable(dev_priv, pll);
15591 if (IS_VALLEYVIEW(dev))
15592 vlv_wm_get_hw_state(dev);
15593 else if (IS_GEN9(dev))
15594 skl_wm_get_hw_state(dev);
15595 else if (HAS_PCH_SPLIT(dev))
15596 ilk_wm_get_hw_state(dev);
15598 for_each_intel_crtc(dev, crtc) {
15599 unsigned long put_domains;
15601 put_domains = modeset_get_crtc_power_domains(&crtc->base);
15602 if (WARN_ON(put_domains))
15603 modeset_put_power_domains(dev_priv, put_domains);
15605 intel_display_set_init_power(dev_priv, false);
15608 void intel_display_resume(struct drm_device *dev)
15610 struct drm_atomic_state *state = drm_atomic_state_alloc(dev);
15611 struct intel_connector *conn;
15612 struct intel_plane *plane;
15613 struct drm_crtc *crtc;
15619 state->acquire_ctx = dev->mode_config.acquire_ctx;
15621 /* preserve complete old state, including dpll */
15622 intel_atomic_get_shared_dpll_state(state);
15624 for_each_crtc(dev, crtc) {
15625 struct drm_crtc_state *crtc_state =
15626 drm_atomic_get_crtc_state(state, crtc);
15628 ret = PTR_ERR_OR_ZERO(crtc_state);
15632 /* force a restore */
15633 crtc_state->mode_changed = true;
15636 for_each_intel_plane(dev, plane) {
15637 ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(state, &plane->base));
15642 for_each_intel_connector(dev, conn) {
15643 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(state, &conn->base));
15648 intel_modeset_setup_hw_state(dev);
15650 i915_redisable_vga(dev);
15651 ret = intel_set_mode(state);
15656 DRM_ERROR("Restoring old state failed with %i\n", ret);
15657 drm_atomic_state_free(state);
15660 void intel_modeset_gem_init(struct drm_device *dev)
15662 struct drm_i915_private *dev_priv = dev->dev_private;
15663 struct drm_crtc *c;
15664 struct drm_i915_gem_object *obj;
15667 mutex_lock(&dev->struct_mutex);
15668 intel_init_gt_powersave(dev);
15669 mutex_unlock(&dev->struct_mutex);
15672 * There may be no VBT; and if the BIOS enabled SSC we can
15673 * just keep using it to avoid unnecessary flicker. Whereas if the
15674 * BIOS isn't using it, don't assume it will work even if the VBT
15675 * indicates as much.
15677 if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
15678 dev_priv->vbt.lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
15681 intel_modeset_init_hw(dev);
15683 intel_setup_overlay(dev);
15686 * Make sure any fbs we allocated at startup are properly
15687 * pinned & fenced. When we do the allocation it's too early
15690 for_each_crtc(dev, c) {
15691 obj = intel_fb_obj(c->primary->fb);
15695 mutex_lock(&dev->struct_mutex);
15696 ret = intel_pin_and_fence_fb_obj(c->primary,
15700 mutex_unlock(&dev->struct_mutex);
15702 DRM_ERROR("failed to pin boot fb on pipe %d\n",
15703 to_intel_crtc(c)->pipe);
15704 drm_framebuffer_unreference(c->primary->fb);
15705 c->primary->fb = NULL;
15706 c->primary->crtc = c->primary->state->crtc = NULL;
15707 update_state_fb(c->primary);
15708 c->state->plane_mask &= ~(1 << drm_plane_index(c->primary));
15712 intel_backlight_register(dev);
15715 void intel_connector_unregister(struct intel_connector *intel_connector)
15717 struct drm_connector *connector = &intel_connector->base;
15719 intel_panel_destroy_backlight(connector);
15720 drm_connector_unregister(connector);
15723 void intel_modeset_cleanup(struct drm_device *dev)
15725 struct drm_i915_private *dev_priv = dev->dev_private;
15726 struct drm_connector *connector;
15728 intel_disable_gt_powersave(dev);
15730 intel_backlight_unregister(dev);
15733 * Interrupts and polling as the first thing to avoid creating havoc.
15734 * Too much stuff here (turning of connectors, ...) would
15735 * experience fancy races otherwise.
15737 intel_irq_uninstall(dev_priv);
15740 * Due to the hpd irq storm handling the hotplug work can re-arm the
15741 * poll handlers. Hence disable polling after hpd handling is shut down.
15743 drm_kms_helper_poll_fini(dev);
15745 intel_unregister_dsm_handler();
15747 intel_fbc_disable(dev_priv);
15749 /* flush any delayed tasks or pending work */
15750 flush_scheduled_work();
15752 /* destroy the backlight and sysfs files before encoders/connectors */
15753 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
15754 struct intel_connector *intel_connector;
15756 intel_connector = to_intel_connector(connector);
15757 intel_connector->unregister(intel_connector);
15760 drm_mode_config_cleanup(dev);
15762 intel_cleanup_overlay(dev);
15764 mutex_lock(&dev->struct_mutex);
15765 intel_cleanup_gt_powersave(dev);
15766 mutex_unlock(&dev->struct_mutex);
15770 * Return which encoder is currently attached for connector.
15772 struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
15774 return &intel_attached_encoder(connector)->base;
15777 void intel_connector_attach_encoder(struct intel_connector *connector,
15778 struct intel_encoder *encoder)
15780 connector->encoder = encoder;
15781 drm_mode_connector_attach_encoder(&connector->base,
15786 * set vga decode state - true == enable VGA decode
15788 int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
15790 struct drm_i915_private *dev_priv = dev->dev_private;
15791 unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
15794 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
15795 DRM_ERROR("failed to read control word\n");
15799 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
15803 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
15805 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
15807 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
15808 DRM_ERROR("failed to write control word\n");
15815 struct intel_display_error_state {
15817 u32 power_well_driver;
15819 int num_transcoders;
15821 struct intel_cursor_error_state {
15826 } cursor[I915_MAX_PIPES];
15828 struct intel_pipe_error_state {
15829 bool power_domain_on;
15832 } pipe[I915_MAX_PIPES];
15834 struct intel_plane_error_state {
15842 } plane[I915_MAX_PIPES];
15844 struct intel_transcoder_error_state {
15845 bool power_domain_on;
15846 enum transcoder cpu_transcoder;
15859 struct intel_display_error_state *
15860 intel_display_capture_error_state(struct drm_device *dev)
15862 struct drm_i915_private *dev_priv = dev->dev_private;
15863 struct intel_display_error_state *error;
15864 int transcoders[] = {
15872 if (INTEL_INFO(dev)->num_pipes == 0)
15875 error = kzalloc(sizeof(*error), GFP_ATOMIC);
15879 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
15880 error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER);
15882 for_each_pipe(dev_priv, i) {
15883 error->pipe[i].power_domain_on =
15884 __intel_display_power_is_enabled(dev_priv,
15885 POWER_DOMAIN_PIPE(i));
15886 if (!error->pipe[i].power_domain_on)
15889 error->cursor[i].control = I915_READ(CURCNTR(i));
15890 error->cursor[i].position = I915_READ(CURPOS(i));
15891 error->cursor[i].base = I915_READ(CURBASE(i));
15893 error->plane[i].control = I915_READ(DSPCNTR(i));
15894 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
15895 if (INTEL_INFO(dev)->gen <= 3) {
15896 error->plane[i].size = I915_READ(DSPSIZE(i));
15897 error->plane[i].pos = I915_READ(DSPPOS(i));
15899 if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
15900 error->plane[i].addr = I915_READ(DSPADDR(i));
15901 if (INTEL_INFO(dev)->gen >= 4) {
15902 error->plane[i].surface = I915_READ(DSPSURF(i));
15903 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
15906 error->pipe[i].source = I915_READ(PIPESRC(i));
15908 if (HAS_GMCH_DISPLAY(dev))
15909 error->pipe[i].stat = I915_READ(PIPESTAT(i));
15912 error->num_transcoders = INTEL_INFO(dev)->num_pipes;
15913 if (HAS_DDI(dev_priv->dev))
15914 error->num_transcoders++; /* Account for eDP. */
15916 for (i = 0; i < error->num_transcoders; i++) {
15917 enum transcoder cpu_transcoder = transcoders[i];
15919 error->transcoder[i].power_domain_on =
15920 __intel_display_power_is_enabled(dev_priv,
15921 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
15922 if (!error->transcoder[i].power_domain_on)
15925 error->transcoder[i].cpu_transcoder = cpu_transcoder;
15927 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
15928 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
15929 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
15930 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
15931 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
15932 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
15933 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
15939 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
15942 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
15943 struct drm_device *dev,
15944 struct intel_display_error_state *error)
15946 struct drm_i915_private *dev_priv = dev->dev_private;
15952 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes);
15953 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
15954 err_printf(m, "PWR_WELL_CTL2: %08x\n",
15955 error->power_well_driver);
15956 for_each_pipe(dev_priv, i) {
15957 err_printf(m, "Pipe [%d]:\n", i);
15958 err_printf(m, " Power: %s\n",
15959 error->pipe[i].power_domain_on ? "on" : "off");
15960 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
15961 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
15963 err_printf(m, "Plane [%d]:\n", i);
15964 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
15965 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
15966 if (INTEL_INFO(dev)->gen <= 3) {
15967 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
15968 err_printf(m, " POS: %08x\n", error->plane[i].pos);
15970 if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
15971 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
15972 if (INTEL_INFO(dev)->gen >= 4) {
15973 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
15974 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
15977 err_printf(m, "Cursor [%d]:\n", i);
15978 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
15979 err_printf(m, " POS: %08x\n", error->cursor[i].position);
15980 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
15983 for (i = 0; i < error->num_transcoders; i++) {
15984 err_printf(m, "CPU transcoder: %c\n",
15985 transcoder_name(error->transcoder[i].cpu_transcoder));
15986 err_printf(m, " Power: %s\n",
15987 error->transcoder[i].power_domain_on ? "on" : "off");
15988 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
15989 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
15990 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
15991 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
15992 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
15993 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
15994 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
15998 void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file)
16000 struct intel_crtc *crtc;
16002 for_each_intel_crtc(dev, crtc) {
16003 struct intel_unpin_work *work;
16005 spin_lock_irq(&dev->event_lock);
16007 work = crtc->unpin_work;
16009 if (work && work->event &&
16010 work->event->base.file_priv == file) {
16011 kfree(work->event);
16012 work->event = NULL;
16015 spin_unlock_irq(&dev->event_lock);