1 /*
2 * Copyright © 2006-2007 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 */
26
27 #include <linux/dma-resv.h>
28 #include <linux/i2c.h>
29 #include <linux/input.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/slab.h>
33 #include <linux/string_helpers.h>
34
35 #include <drm/display/drm_dp_helper.h>
36 #include <drm/display/drm_dp_tunnel.h>
37 #include <drm/drm_atomic.h>
38 #include <drm/drm_atomic_helper.h>
39 #include <drm/drm_atomic_uapi.h>
40 #include <drm/drm_damage_helper.h>
41 #include <drm/drm_edid.h>
42 #include <drm/drm_fixed.h>
43 #include <drm/drm_fourcc.h>
44 #include <drm/drm_probe_helper.h>
45 #include <drm/drm_rect.h>
46 #include <drm/drm_vblank.h>
47
48 #include "g4x_dp.h"
49 #include "g4x_hdmi.h"
50 #include "hsw_ips.h"
51 #include "i915_config.h"
52 #include "i915_drv.h"
53 #include "i915_reg.h"
54 #include "i915_utils.h"
55 #include "i9xx_plane.h"
56 #include "i9xx_plane_regs.h"
57 #include "i9xx_wm.h"
58 #include "intel_alpm.h"
59 #include "intel_atomic.h"
60 #include "intel_atomic_plane.h"
61 #include "intel_audio.h"
62 #include "intel_bo.h"
63 #include "intel_bw.h"
64 #include "intel_cdclk.h"
65 #include "intel_clock_gating.h"
66 #include "intel_color.h"
67 #include "intel_crt.h"
68 #include "intel_crtc.h"
69 #include "intel_crtc_state_dump.h"
70 #include "intel_cursor_regs.h"
71 #include "intel_cx0_phy.h"
72 #include "intel_cursor.h"
73 #include "intel_ddi.h"
74 #include "intel_de.h"
75 #include "intel_display_driver.h"
76 #include "intel_display_power.h"
77 #include "intel_display_rpm.h"
78 #include "intel_display_types.h"
79 #include "intel_dmc.h"
80 #include "intel_dp.h"
81 #include "intel_dp_link_training.h"
82 #include "intel_dp_mst.h"
83 #include "intel_dp_tunnel.h"
84 #include "intel_dpll.h"
85 #include "intel_dpll_mgr.h"
86 #include "intel_dpt.h"
87 #include "intel_dpt_common.h"
88 #include "intel_drrs.h"
89 #include "intel_dsb.h"
90 #include "intel_dsi.h"
91 #include "intel_dvo.h"
92 #include "intel_fb.h"
93 #include "intel_fbc.h"
94 #include "intel_fdi.h"
95 #include "intel_fifo_underrun.h"
96 #include "intel_frontbuffer.h"
97 #include "intel_hdmi.h"
98 #include "intel_hotplug.h"
99 #include "intel_link_bw.h"
100 #include "intel_lvds.h"
101 #include "intel_lvds_regs.h"
102 #include "intel_modeset_setup.h"
103 #include "intel_modeset_verify.h"
104 #include "intel_overlay.h"
105 #include "intel_panel.h"
106 #include "intel_pch_display.h"
107 #include "intel_pch_refclk.h"
108 #include "intel_pcode.h"
109 #include "intel_pfit.h"
110 #include "intel_pipe_crc.h"
111 #include "intel_plane_initial.h"
112 #include "intel_pmdemand.h"
113 #include "intel_pps.h"
114 #include "intel_psr.h"
115 #include "intel_psr_regs.h"
116 #include "intel_sdvo.h"
117 #include "intel_snps_phy.h"
118 #include "intel_tc.h"
119 #include "intel_tdf.h"
120 #include "intel_tv.h"
121 #include "intel_vblank.h"
122 #include "intel_vdsc.h"
123 #include "intel_vdsc_regs.h"
124 #include "intel_vga.h"
125 #include "intel_vrr.h"
126 #include "intel_wm.h"
127 #include "skl_scaler.h"
128 #include "skl_universal_plane.h"
129 #include "skl_watermark.h"
130 #include "vlv_dpio_phy_regs.h"
131 #include "vlv_dsi.h"
132 #include "vlv_dsi_pll.h"
133 #include "vlv_dsi_regs.h"
134 #include "vlv_sideband.h"
135
136 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state);
137 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
138 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state);
139 static void bdw_set_pipe_misc(struct intel_dsb *dsb,
140 const struct intel_crtc_state *crtc_state);
141
142 /* returns HPLL frequency in kHz */
vlv_get_hpll_vco(struct drm_i915_private * dev_priv)143 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
144 {
145 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
146
147 /* Obtain SKU information */
148 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
149 CCK_FUSE_HPLL_FREQ_MASK;
150
151 return vco_freq[hpll_freq] * 1000;
152 }
153
vlv_get_cck_clock(struct drm_i915_private * dev_priv,const char * name,u32 reg,int ref_freq)154 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
155 const char *name, u32 reg, int ref_freq)
156 {
157 u32 val;
158 int divider;
159
160 val = vlv_cck_read(dev_priv, reg);
161 divider = val & CCK_FREQUENCY_VALUES;
162
163 drm_WARN(&dev_priv->drm, (val & CCK_FREQUENCY_STATUS) !=
164 (divider << CCK_FREQUENCY_STATUS_SHIFT),
165 "%s change in progress\n", name);
166
167 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
168 }
169
vlv_get_cck_clock_hpll(struct drm_i915_private * dev_priv,const char * name,u32 reg)170 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
171 const char *name, u32 reg)
172 {
173 int hpll;
174
175 vlv_cck_get(dev_priv);
176
177 if (dev_priv->hpll_freq == 0)
178 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
179
180 hpll = vlv_get_cck_clock(dev_priv, name, reg, dev_priv->hpll_freq);
181
182 vlv_cck_put(dev_priv);
183
184 return hpll;
185 }
186
intel_update_czclk(struct intel_display * display)187 void intel_update_czclk(struct intel_display *display)
188 {
189 struct drm_i915_private *dev_priv = to_i915(display->drm);
190
191 if (!display->platform.valleyview && !display->platform.cherryview)
192 return;
193
194 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
195 CCK_CZ_CLOCK_CONTROL);
196
197 drm_dbg_kms(display->drm, "CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
198 }
199
is_hdr_mode(const struct intel_crtc_state * crtc_state)200 static bool is_hdr_mode(const struct intel_crtc_state *crtc_state)
201 {
202 return (crtc_state->active_planes &
203 ~(icl_hdr_plane_mask() | BIT(PLANE_CURSOR))) == 0;
204 }
205
206 /* WA Display #0827: Gen9:all */
207 static void
skl_wa_827(struct intel_display * display,enum pipe pipe,bool enable)208 skl_wa_827(struct intel_display *display, enum pipe pipe, bool enable)
209 {
210 intel_de_rmw(display, CLKGATE_DIS_PSL(pipe),
211 DUPS1_GATING_DIS | DUPS2_GATING_DIS,
212 enable ? DUPS1_GATING_DIS | DUPS2_GATING_DIS : 0);
213 }
214
215 /* Wa_2006604312:icl,ehl */
216 static void
icl_wa_scalerclkgating(struct intel_display * display,enum pipe pipe,bool enable)217 icl_wa_scalerclkgating(struct intel_display *display, enum pipe pipe,
218 bool enable)
219 {
220 intel_de_rmw(display, CLKGATE_DIS_PSL(pipe),
221 DPFR_GATING_DIS,
222 enable ? DPFR_GATING_DIS : 0);
223 }
224
225 /* Wa_1604331009:icl,jsl,ehl */
226 static void
icl_wa_cursorclkgating(struct intel_display * display,enum pipe pipe,bool enable)227 icl_wa_cursorclkgating(struct intel_display *display, enum pipe pipe,
228 bool enable)
229 {
230 intel_de_rmw(display, CLKGATE_DIS_PSL(pipe),
231 CURSOR_GATING_DIS,
232 enable ? CURSOR_GATING_DIS : 0);
233 }
234
235 static bool
is_trans_port_sync_slave(const struct intel_crtc_state * crtc_state)236 is_trans_port_sync_slave(const struct intel_crtc_state *crtc_state)
237 {
238 return crtc_state->master_transcoder != INVALID_TRANSCODER;
239 }
240
241 bool
is_trans_port_sync_master(const struct intel_crtc_state * crtc_state)242 is_trans_port_sync_master(const struct intel_crtc_state *crtc_state)
243 {
244 return crtc_state->sync_mode_slaves_mask != 0;
245 }
246
247 bool
is_trans_port_sync_mode(const struct intel_crtc_state * crtc_state)248 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state)
249 {
250 return is_trans_port_sync_master(crtc_state) ||
251 is_trans_port_sync_slave(crtc_state);
252 }
253
joiner_primary_pipe(const struct intel_crtc_state * crtc_state)254 static enum pipe joiner_primary_pipe(const struct intel_crtc_state *crtc_state)
255 {
256 return ffs(crtc_state->joiner_pipes) - 1;
257 }
258
259 /*
260 * The following helper functions, despite being named for bigjoiner,
261 * are applicable to both bigjoiner and uncompressed joiner configurations.
262 */
is_bigjoiner(const struct intel_crtc_state * crtc_state)263 static bool is_bigjoiner(const struct intel_crtc_state *crtc_state)
264 {
265 return hweight8(crtc_state->joiner_pipes) >= 2;
266 }
267
bigjoiner_primary_pipes(const struct intel_crtc_state * crtc_state)268 static u8 bigjoiner_primary_pipes(const struct intel_crtc_state *crtc_state)
269 {
270 if (!is_bigjoiner(crtc_state))
271 return 0;
272
273 return crtc_state->joiner_pipes & (0b01010101 << joiner_primary_pipe(crtc_state));
274 }
275
bigjoiner_secondary_pipes(const struct intel_crtc_state * crtc_state)276 static unsigned int bigjoiner_secondary_pipes(const struct intel_crtc_state *crtc_state)
277 {
278 if (!is_bigjoiner(crtc_state))
279 return 0;
280
281 return crtc_state->joiner_pipes & (0b10101010 << joiner_primary_pipe(crtc_state));
282 }
283
intel_crtc_is_bigjoiner_primary(const struct intel_crtc_state * crtc_state)284 bool intel_crtc_is_bigjoiner_primary(const struct intel_crtc_state *crtc_state)
285 {
286 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
287
288 if (!is_bigjoiner(crtc_state))
289 return false;
290
291 return BIT(crtc->pipe) & bigjoiner_primary_pipes(crtc_state);
292 }
293
intel_crtc_is_bigjoiner_secondary(const struct intel_crtc_state * crtc_state)294 bool intel_crtc_is_bigjoiner_secondary(const struct intel_crtc_state *crtc_state)
295 {
296 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
297
298 if (!is_bigjoiner(crtc_state))
299 return false;
300
301 return BIT(crtc->pipe) & bigjoiner_secondary_pipes(crtc_state);
302 }
303
_intel_modeset_primary_pipes(const struct intel_crtc_state * crtc_state)304 u8 _intel_modeset_primary_pipes(const struct intel_crtc_state *crtc_state)
305 {
306 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
307
308 if (!is_bigjoiner(crtc_state))
309 return BIT(crtc->pipe);
310
311 return bigjoiner_primary_pipes(crtc_state);
312 }
313
_intel_modeset_secondary_pipes(const struct intel_crtc_state * crtc_state)314 u8 _intel_modeset_secondary_pipes(const struct intel_crtc_state *crtc_state)
315 {
316 return bigjoiner_secondary_pipes(crtc_state);
317 }
318
intel_crtc_is_ultrajoiner(const struct intel_crtc_state * crtc_state)319 bool intel_crtc_is_ultrajoiner(const struct intel_crtc_state *crtc_state)
320 {
321 return intel_crtc_num_joined_pipes(crtc_state) >= 4;
322 }
323
ultrajoiner_primary_pipes(const struct intel_crtc_state * crtc_state)324 static u8 ultrajoiner_primary_pipes(const struct intel_crtc_state *crtc_state)
325 {
326 if (!intel_crtc_is_ultrajoiner(crtc_state))
327 return 0;
328
329 return crtc_state->joiner_pipes & (0b00010001 << joiner_primary_pipe(crtc_state));
330 }
331
intel_crtc_is_ultrajoiner_primary(const struct intel_crtc_state * crtc_state)332 bool intel_crtc_is_ultrajoiner_primary(const struct intel_crtc_state *crtc_state)
333 {
334 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
335
336 return intel_crtc_is_ultrajoiner(crtc_state) &&
337 BIT(crtc->pipe) & ultrajoiner_primary_pipes(crtc_state);
338 }
339
340 /*
341 * The ultrajoiner enable bit doesn't seem to follow primary/secondary logic or
342 * any other logic, so lets just add helper function to
343 * at least hide this hassle..
344 */
ultrajoiner_enable_pipes(const struct intel_crtc_state * crtc_state)345 static u8 ultrajoiner_enable_pipes(const struct intel_crtc_state *crtc_state)
346 {
347 if (!intel_crtc_is_ultrajoiner(crtc_state))
348 return 0;
349
350 return crtc_state->joiner_pipes & (0b01110111 << joiner_primary_pipe(crtc_state));
351 }
352
intel_crtc_ultrajoiner_enable_needed(const struct intel_crtc_state * crtc_state)353 bool intel_crtc_ultrajoiner_enable_needed(const struct intel_crtc_state *crtc_state)
354 {
355 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
356
357 return intel_crtc_is_ultrajoiner(crtc_state) &&
358 BIT(crtc->pipe) & ultrajoiner_enable_pipes(crtc_state);
359 }
360
intel_crtc_joiner_secondary_pipes(const struct intel_crtc_state * crtc_state)361 u8 intel_crtc_joiner_secondary_pipes(const struct intel_crtc_state *crtc_state)
362 {
363 if (crtc_state->joiner_pipes)
364 return crtc_state->joiner_pipes & ~BIT(joiner_primary_pipe(crtc_state));
365 else
366 return 0;
367 }
368
intel_crtc_is_joiner_secondary(const struct intel_crtc_state * crtc_state)369 bool intel_crtc_is_joiner_secondary(const struct intel_crtc_state *crtc_state)
370 {
371 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
372
373 return crtc_state->joiner_pipes &&
374 crtc->pipe != joiner_primary_pipe(crtc_state);
375 }
376
intel_crtc_is_joiner_primary(const struct intel_crtc_state * crtc_state)377 bool intel_crtc_is_joiner_primary(const struct intel_crtc_state *crtc_state)
378 {
379 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
380
381 return crtc_state->joiner_pipes &&
382 crtc->pipe == joiner_primary_pipe(crtc_state);
383 }
384
intel_crtc_num_joined_pipes(const struct intel_crtc_state * crtc_state)385 int intel_crtc_num_joined_pipes(const struct intel_crtc_state *crtc_state)
386 {
387 return hweight8(intel_crtc_joined_pipe_mask(crtc_state));
388 }
389
intel_crtc_joined_pipe_mask(const struct intel_crtc_state * crtc_state)390 u8 intel_crtc_joined_pipe_mask(const struct intel_crtc_state *crtc_state)
391 {
392 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
393
394 return BIT(crtc->pipe) | crtc_state->joiner_pipes;
395 }
396
intel_primary_crtc(const struct intel_crtc_state * crtc_state)397 struct intel_crtc *intel_primary_crtc(const struct intel_crtc_state *crtc_state)
398 {
399 struct intel_display *display = to_intel_display(crtc_state);
400
401 if (intel_crtc_is_joiner_secondary(crtc_state))
402 return intel_crtc_for_pipe(display, joiner_primary_pipe(crtc_state));
403 else
404 return to_intel_crtc(crtc_state->uapi.crtc);
405 }
406
407 static void
intel_wait_for_pipe_off(const struct intel_crtc_state * old_crtc_state)408 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
409 {
410 struct intel_display *display = to_intel_display(old_crtc_state);
411 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
412
413 if (DISPLAY_VER(display) >= 4) {
414 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
415
416 /* Wait for the Pipe State to go off */
417 if (intel_de_wait_for_clear(display, TRANSCONF(display, cpu_transcoder),
418 TRANSCONF_STATE_ENABLE, 100))
419 drm_WARN(display->drm, 1, "pipe_off wait timed out\n");
420 } else {
421 intel_wait_for_pipe_scanline_stopped(crtc);
422 }
423 }
424
assert_transcoder(struct intel_display * display,enum transcoder cpu_transcoder,bool state)425 void assert_transcoder(struct intel_display *display,
426 enum transcoder cpu_transcoder, bool state)
427 {
428 bool cur_state;
429 enum intel_display_power_domain power_domain;
430 intel_wakeref_t wakeref;
431
432 /* we keep both pipes enabled on 830 */
433 if (display->platform.i830)
434 state = true;
435
436 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
437 wakeref = intel_display_power_get_if_enabled(display, power_domain);
438 if (wakeref) {
439 u32 val = intel_de_read(display,
440 TRANSCONF(display, cpu_transcoder));
441 cur_state = !!(val & TRANSCONF_ENABLE);
442
443 intel_display_power_put(display, power_domain, wakeref);
444 } else {
445 cur_state = false;
446 }
447
448 INTEL_DISPLAY_STATE_WARN(display, cur_state != state,
449 "transcoder %s assertion failure (expected %s, current %s)\n",
450 transcoder_name(cpu_transcoder), str_on_off(state),
451 str_on_off(cur_state));
452 }
453
assert_plane(struct intel_plane * plane,bool state)454 static void assert_plane(struct intel_plane *plane, bool state)
455 {
456 struct intel_display *display = to_intel_display(plane->base.dev);
457 enum pipe pipe;
458 bool cur_state;
459
460 cur_state = plane->get_hw_state(plane, &pipe);
461
462 INTEL_DISPLAY_STATE_WARN(display, cur_state != state,
463 "%s assertion failure (expected %s, current %s)\n",
464 plane->base.name, str_on_off(state),
465 str_on_off(cur_state));
466 }
467
468 #define assert_plane_enabled(p) assert_plane(p, true)
469 #define assert_plane_disabled(p) assert_plane(p, false)
470
assert_planes_disabled(struct intel_crtc * crtc)471 static void assert_planes_disabled(struct intel_crtc *crtc)
472 {
473 struct intel_display *display = to_intel_display(crtc);
474 struct intel_plane *plane;
475
476 for_each_intel_plane_on_crtc(display->drm, crtc, plane)
477 assert_plane_disabled(plane);
478 }
479
intel_enable_transcoder(const struct intel_crtc_state * new_crtc_state)480 void intel_enable_transcoder(const struct intel_crtc_state *new_crtc_state)
481 {
482 struct intel_display *display = to_intel_display(new_crtc_state);
483 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
484 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
485 enum pipe pipe = crtc->pipe;
486 u32 val;
487
488 drm_dbg_kms(display->drm, "enabling pipe %c\n", pipe_name(pipe));
489
490 assert_planes_disabled(crtc);
491
492 /*
493 * A pipe without a PLL won't actually be able to drive bits from
494 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
495 * need the check.
496 */
497 if (HAS_GMCH(display)) {
498 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
499 assert_dsi_pll_enabled(display);
500 else
501 assert_pll_enabled(display, pipe);
502 } else {
503 if (new_crtc_state->has_pch_encoder) {
504 /* if driving the PCH, we need FDI enabled */
505 assert_fdi_rx_pll_enabled(display,
506 intel_crtc_pch_transcoder(crtc));
507 assert_fdi_tx_pll_enabled(display,
508 (enum pipe) cpu_transcoder);
509 }
510 /* FIXME: assert CPU port conditions for SNB+ */
511 }
512
513 /* Wa_22012358565:adl-p */
514 if (DISPLAY_VER(display) == 13)
515 intel_de_rmw(display, PIPE_ARB_CTL(display, pipe),
516 0, PIPE_ARB_USE_PROG_SLOTS);
517
518 if (DISPLAY_VER(display) >= 14) {
519 u32 clear = DP_DSC_INSERT_SF_AT_EOL_WA;
520 u32 set = 0;
521
522 if (DISPLAY_VER(display) == 14)
523 set |= DP_FEC_BS_JITTER_WA;
524
525 intel_de_rmw(display, CHICKEN_TRANS(display, cpu_transcoder),
526 clear, set);
527 }
528
529 val = intel_de_read(display, TRANSCONF(display, cpu_transcoder));
530 if (val & TRANSCONF_ENABLE) {
531 /* we keep both pipes enabled on 830 */
532 drm_WARN_ON(display->drm, !display->platform.i830);
533 return;
534 }
535
536 /* Wa_1409098942:adlp+ */
537 if (DISPLAY_VER(display) >= 13 &&
538 new_crtc_state->dsc.compression_enable) {
539 val &= ~TRANSCONF_PIXEL_COUNT_SCALING_MASK;
540 val |= REG_FIELD_PREP(TRANSCONF_PIXEL_COUNT_SCALING_MASK,
541 TRANSCONF_PIXEL_COUNT_SCALING_X4);
542 }
543
544 intel_de_write(display, TRANSCONF(display, cpu_transcoder),
545 val | TRANSCONF_ENABLE);
546 intel_de_posting_read(display, TRANSCONF(display, cpu_transcoder));
547
548 /*
549 * Until the pipe starts PIPEDSL reads will return a stale value,
550 * which causes an apparent vblank timestamp jump when PIPEDSL
551 * resets to its proper value. That also messes up the frame count
552 * when it's derived from the timestamps. So let's wait for the
553 * pipe to start properly before we call drm_crtc_vblank_on()
554 */
555 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
556 intel_wait_for_pipe_scanline_moving(crtc);
557 }
558
intel_disable_transcoder(const struct intel_crtc_state * old_crtc_state)559 void intel_disable_transcoder(const struct intel_crtc_state *old_crtc_state)
560 {
561 struct intel_display *display = to_intel_display(old_crtc_state);
562 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
563 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
564 enum pipe pipe = crtc->pipe;
565 u32 val;
566
567 drm_dbg_kms(display->drm, "disabling pipe %c\n", pipe_name(pipe));
568
569 /*
570 * Make sure planes won't keep trying to pump pixels to us,
571 * or we might hang the display.
572 */
573 assert_planes_disabled(crtc);
574
575 val = intel_de_read(display, TRANSCONF(display, cpu_transcoder));
576 if ((val & TRANSCONF_ENABLE) == 0)
577 return;
578
579 /*
580 * Double wide has implications for planes
581 * so best keep it disabled when not needed.
582 */
583 if (old_crtc_state->double_wide)
584 val &= ~TRANSCONF_DOUBLE_WIDE;
585
586 /* Don't disable pipe or pipe PLLs if needed */
587 if (!display->platform.i830)
588 val &= ~TRANSCONF_ENABLE;
589
590 /* Wa_1409098942:adlp+ */
591 if (DISPLAY_VER(display) >= 13 &&
592 old_crtc_state->dsc.compression_enable)
593 val &= ~TRANSCONF_PIXEL_COUNT_SCALING_MASK;
594
595 intel_de_write(display, TRANSCONF(display, cpu_transcoder), val);
596
597 if (DISPLAY_VER(display) >= 12)
598 intel_de_rmw(display, CHICKEN_TRANS(display, cpu_transcoder),
599 FECSTALL_DIS_DPTSTREAM_DPTTG, 0);
600
601 if ((val & TRANSCONF_ENABLE) == 0)
602 intel_wait_for_pipe_off(old_crtc_state);
603 }
604
intel_plane_fb_max_stride(struct drm_device * drm,u32 pixel_format,u64 modifier)605 u32 intel_plane_fb_max_stride(struct drm_device *drm,
606 u32 pixel_format, u64 modifier)
607 {
608 struct intel_display *display = to_intel_display(drm);
609 struct intel_crtc *crtc;
610 struct intel_plane *plane;
611
612 if (!HAS_DISPLAY(display))
613 return 0;
614
615 /*
616 * We assume the primary plane for pipe A has
617 * the highest stride limits of them all,
618 * if in case pipe A is disabled, use the first pipe from pipe_mask.
619 */
620 crtc = intel_first_crtc(display);
621 if (!crtc)
622 return 0;
623
624 plane = to_intel_plane(crtc->base.primary);
625
626 return plane->max_stride(plane, pixel_format, modifier,
627 DRM_MODE_ROTATE_0);
628 }
629
intel_set_plane_visible(struct intel_crtc_state * crtc_state,struct intel_plane_state * plane_state,bool visible)630 void intel_set_plane_visible(struct intel_crtc_state *crtc_state,
631 struct intel_plane_state *plane_state,
632 bool visible)
633 {
634 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
635
636 plane_state->uapi.visible = visible;
637
638 if (visible)
639 crtc_state->uapi.plane_mask |= drm_plane_mask(&plane->base);
640 else
641 crtc_state->uapi.plane_mask &= ~drm_plane_mask(&plane->base);
642 }
643
intel_plane_fixup_bitmasks(struct intel_crtc_state * crtc_state)644 void intel_plane_fixup_bitmasks(struct intel_crtc_state *crtc_state)
645 {
646 struct intel_display *display = to_intel_display(crtc_state);
647 struct drm_plane *plane;
648
649 /*
650 * Active_planes aliases if multiple "primary" or cursor planes
651 * have been used on the same (or wrong) pipe. plane_mask uses
652 * unique ids, hence we can use that to reconstruct active_planes.
653 */
654 crtc_state->enabled_planes = 0;
655 crtc_state->active_planes = 0;
656
657 drm_for_each_plane_mask(plane, display->drm,
658 crtc_state->uapi.plane_mask) {
659 crtc_state->enabled_planes |= BIT(to_intel_plane(plane)->id);
660 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
661 }
662 }
663
intel_plane_disable_noatomic(struct intel_crtc * crtc,struct intel_plane * plane)664 void intel_plane_disable_noatomic(struct intel_crtc *crtc,
665 struct intel_plane *plane)
666 {
667 struct intel_display *display = to_intel_display(crtc);
668 struct intel_crtc_state *crtc_state =
669 to_intel_crtc_state(crtc->base.state);
670 struct intel_plane_state *plane_state =
671 to_intel_plane_state(plane->base.state);
672
673 drm_dbg_kms(display->drm,
674 "Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
675 plane->base.base.id, plane->base.name,
676 crtc->base.base.id, crtc->base.name);
677
678 intel_plane_set_invisible(crtc_state, plane_state);
679 intel_set_plane_visible(crtc_state, plane_state, false);
680 intel_plane_fixup_bitmasks(crtc_state);
681
682 skl_wm_plane_disable_noatomic(crtc, plane);
683
684 if ((crtc_state->active_planes & ~BIT(PLANE_CURSOR)) == 0 &&
685 hsw_ips_disable(crtc_state)) {
686 crtc_state->ips_enabled = false;
687 intel_plane_initial_vblank_wait(crtc);
688 }
689
690 /*
691 * Vblank time updates from the shadow to live plane control register
692 * are blocked if the memory self-refresh mode is active at that
693 * moment. So to make sure the plane gets truly disabled, disable
694 * first the self-refresh mode. The self-refresh enable bit in turn
695 * will be checked/applied by the HW only at the next frame start
696 * event which is after the vblank start event, so we need to have a
697 * wait-for-vblank between disabling the plane and the pipe.
698 */
699 if (HAS_GMCH(display) &&
700 intel_set_memory_cxsr(display, false))
701 intel_plane_initial_vblank_wait(crtc);
702
703 /*
704 * Gen2 reports pipe underruns whenever all planes are disabled.
705 * So disable underrun reporting before all the planes get disabled.
706 */
707 if (DISPLAY_VER(display) == 2 && !crtc_state->active_planes)
708 intel_set_cpu_fifo_underrun_reporting(display, crtc->pipe, false);
709
710 intel_plane_disable_arm(NULL, plane, crtc_state);
711 intel_plane_initial_vblank_wait(crtc);
712 }
713
714 unsigned int
intel_plane_fence_y_offset(const struct intel_plane_state * plane_state)715 intel_plane_fence_y_offset(const struct intel_plane_state *plane_state)
716 {
717 int x = 0, y = 0;
718
719 intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
720 plane_state->view.color_plane[0].offset, 0);
721
722 return y;
723 }
724
icl_set_pipe_chicken(const struct intel_crtc_state * crtc_state)725 static void icl_set_pipe_chicken(const struct intel_crtc_state *crtc_state)
726 {
727 struct intel_display *display = to_intel_display(crtc_state);
728 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
729 enum pipe pipe = crtc->pipe;
730 u32 tmp;
731
732 tmp = intel_de_read(display, PIPE_CHICKEN(pipe));
733
734 /*
735 * Display WA #1153: icl
736 * enable hardware to bypass the alpha math
737 * and rounding for per-pixel values 00 and 0xff
738 */
739 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
740 /*
741 * Display WA # 1605353570: icl
742 * Set the pixel rounding bit to 1 for allowing
743 * passthrough of Frame buffer pixels unmodified
744 * across pipe
745 */
746 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
747
748 /*
749 * Underrun recovery must always be disabled on display 13+.
750 * DG2 chicken bit meaning is inverted compared to other platforms.
751 */
752 if (display->platform.dg2)
753 tmp &= ~UNDERRUN_RECOVERY_ENABLE_DG2;
754 else if ((DISPLAY_VER(display) >= 13) && (DISPLAY_VER(display) < 30))
755 tmp |= UNDERRUN_RECOVERY_DISABLE_ADLP;
756
757 /* Wa_14010547955:dg2 */
758 if (display->platform.dg2)
759 tmp |= DG2_RENDER_CCSTAG_4_3_EN;
760
761 intel_de_write(display, PIPE_CHICKEN(pipe), tmp);
762 }
763
intel_has_pending_fb_unpin(struct intel_display * display)764 bool intel_has_pending_fb_unpin(struct intel_display *display)
765 {
766 struct drm_crtc *crtc;
767 bool cleanup_done;
768
769 drm_for_each_crtc(crtc, display->drm) {
770 struct drm_crtc_commit *commit;
771 spin_lock(&crtc->commit_lock);
772 commit = list_first_entry_or_null(&crtc->commit_list,
773 struct drm_crtc_commit, commit_entry);
774 cleanup_done = commit ?
775 try_wait_for_completion(&commit->cleanup_done) : true;
776 spin_unlock(&crtc->commit_lock);
777
778 if (cleanup_done)
779 continue;
780
781 intel_crtc_wait_for_next_vblank(to_intel_crtc(crtc));
782
783 return true;
784 }
785
786 return false;
787 }
788
789 /*
790 * Finds the encoder associated with the given CRTC. This can only be
791 * used when we know that the CRTC isn't feeding multiple encoders!
792 */
793 struct intel_encoder *
intel_get_crtc_new_encoder(const struct intel_atomic_state * state,const struct intel_crtc_state * crtc_state)794 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
795 const struct intel_crtc_state *crtc_state)
796 {
797 const struct drm_connector_state *connector_state;
798 const struct drm_connector *connector;
799 struct intel_encoder *encoder = NULL;
800 struct intel_crtc *primary_crtc;
801 int num_encoders = 0;
802 int i;
803
804 primary_crtc = intel_primary_crtc(crtc_state);
805
806 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
807 if (connector_state->crtc != &primary_crtc->base)
808 continue;
809
810 encoder = to_intel_encoder(connector_state->best_encoder);
811 num_encoders++;
812 }
813
814 drm_WARN(state->base.dev, num_encoders != 1,
815 "%d encoders for pipe %c\n",
816 num_encoders, pipe_name(primary_crtc->pipe));
817
818 return encoder;
819 }
820
intel_crtc_dpms_overlay_disable(struct intel_crtc * crtc)821 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *crtc)
822 {
823 if (crtc->overlay)
824 (void) intel_overlay_switch_off(crtc->overlay);
825
826 /* Let userspace switch the overlay on again. In most cases userspace
827 * has to recompute where to put it anyway.
828 */
829 }
830
needs_nv12_wa(const struct intel_crtc_state * crtc_state)831 static bool needs_nv12_wa(const struct intel_crtc_state *crtc_state)
832 {
833 struct intel_display *display = to_intel_display(crtc_state);
834
835 if (!crtc_state->nv12_planes)
836 return false;
837
838 /* WA Display #0827: Gen9:all */
839 if (DISPLAY_VER(display) == 9)
840 return true;
841
842 return false;
843 }
844
needs_scalerclk_wa(const struct intel_crtc_state * crtc_state)845 static bool needs_scalerclk_wa(const struct intel_crtc_state *crtc_state)
846 {
847 struct intel_display *display = to_intel_display(crtc_state);
848
849 /* Wa_2006604312:icl,ehl */
850 if (crtc_state->scaler_state.scaler_users > 0 && DISPLAY_VER(display) == 11)
851 return true;
852
853 return false;
854 }
855
needs_cursorclk_wa(const struct intel_crtc_state * crtc_state)856 static bool needs_cursorclk_wa(const struct intel_crtc_state *crtc_state)
857 {
858 struct intel_display *display = to_intel_display(crtc_state);
859
860 /* Wa_1604331009:icl,jsl,ehl */
861 if (is_hdr_mode(crtc_state) &&
862 crtc_state->active_planes & BIT(PLANE_CURSOR) &&
863 DISPLAY_VER(display) == 11)
864 return true;
865
866 return false;
867 }
868
intel_async_flip_vtd_wa(struct intel_display * display,enum pipe pipe,bool enable)869 static void intel_async_flip_vtd_wa(struct intel_display *display,
870 enum pipe pipe, bool enable)
871 {
872 if (DISPLAY_VER(display) == 9) {
873 /*
874 * "Plane N stretch max must be programmed to 11b (x1)
875 * when Async flips are enabled on that plane."
876 */
877 intel_de_rmw(display, CHICKEN_PIPESL_1(pipe),
878 SKL_PLANE1_STRETCH_MAX_MASK,
879 enable ? SKL_PLANE1_STRETCH_MAX_X1 : SKL_PLANE1_STRETCH_MAX_X8);
880 } else {
881 /* Also needed on HSW/BDW albeit undocumented */
882 intel_de_rmw(display, CHICKEN_PIPESL_1(pipe),
883 HSW_PRI_STRETCH_MAX_MASK,
884 enable ? HSW_PRI_STRETCH_MAX_X1 : HSW_PRI_STRETCH_MAX_X8);
885 }
886 }
887
needs_async_flip_vtd_wa(const struct intel_crtc_state * crtc_state)888 static bool needs_async_flip_vtd_wa(const struct intel_crtc_state *crtc_state)
889 {
890 struct intel_display *display = to_intel_display(crtc_state);
891 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
892
893 return crtc_state->uapi.async_flip && i915_vtd_active(i915) &&
894 (DISPLAY_VER(display) == 9 || display->platform.broadwell ||
895 display->platform.haswell);
896 }
897
intel_encoders_audio_enable(struct intel_atomic_state * state,struct intel_crtc * crtc)898 static void intel_encoders_audio_enable(struct intel_atomic_state *state,
899 struct intel_crtc *crtc)
900 {
901 const struct intel_crtc_state *crtc_state =
902 intel_atomic_get_new_crtc_state(state, crtc);
903 const struct drm_connector_state *conn_state;
904 struct drm_connector *conn;
905 int i;
906
907 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
908 struct intel_encoder *encoder =
909 to_intel_encoder(conn_state->best_encoder);
910
911 if (conn_state->crtc != &crtc->base)
912 continue;
913
914 if (encoder->audio_enable)
915 encoder->audio_enable(encoder, crtc_state, conn_state);
916 }
917 }
918
intel_encoders_audio_disable(struct intel_atomic_state * state,struct intel_crtc * crtc)919 static void intel_encoders_audio_disable(struct intel_atomic_state *state,
920 struct intel_crtc *crtc)
921 {
922 const struct intel_crtc_state *old_crtc_state =
923 intel_atomic_get_old_crtc_state(state, crtc);
924 const struct drm_connector_state *old_conn_state;
925 struct drm_connector *conn;
926 int i;
927
928 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
929 struct intel_encoder *encoder =
930 to_intel_encoder(old_conn_state->best_encoder);
931
932 if (old_conn_state->crtc != &crtc->base)
933 continue;
934
935 if (encoder->audio_disable)
936 encoder->audio_disable(encoder, old_crtc_state, old_conn_state);
937 }
938 }
939
940 #define is_enabling(feature, old_crtc_state, new_crtc_state) \
941 ((!(old_crtc_state)->feature || intel_crtc_needs_modeset(new_crtc_state)) && \
942 (new_crtc_state)->feature)
943 #define is_disabling(feature, old_crtc_state, new_crtc_state) \
944 ((old_crtc_state)->feature && \
945 (!(new_crtc_state)->feature || intel_crtc_needs_modeset(new_crtc_state)))
946
planes_enabling(const struct intel_crtc_state * old_crtc_state,const struct intel_crtc_state * new_crtc_state)947 static bool planes_enabling(const struct intel_crtc_state *old_crtc_state,
948 const struct intel_crtc_state *new_crtc_state)
949 {
950 if (!new_crtc_state->hw.active)
951 return false;
952
953 return is_enabling(active_planes, old_crtc_state, new_crtc_state);
954 }
955
planes_disabling(const struct intel_crtc_state * old_crtc_state,const struct intel_crtc_state * new_crtc_state)956 static bool planes_disabling(const struct intel_crtc_state *old_crtc_state,
957 const struct intel_crtc_state *new_crtc_state)
958 {
959 if (!old_crtc_state->hw.active)
960 return false;
961
962 return is_disabling(active_planes, old_crtc_state, new_crtc_state);
963 }
964
vrr_params_changed(const struct intel_crtc_state * old_crtc_state,const struct intel_crtc_state * new_crtc_state)965 static bool vrr_params_changed(const struct intel_crtc_state *old_crtc_state,
966 const struct intel_crtc_state *new_crtc_state)
967 {
968 return old_crtc_state->vrr.flipline != new_crtc_state->vrr.flipline ||
969 old_crtc_state->vrr.vmin != new_crtc_state->vrr.vmin ||
970 old_crtc_state->vrr.vmax != new_crtc_state->vrr.vmax ||
971 old_crtc_state->vrr.guardband != new_crtc_state->vrr.guardband ||
972 old_crtc_state->vrr.pipeline_full != new_crtc_state->vrr.pipeline_full ||
973 old_crtc_state->vrr.vsync_start != new_crtc_state->vrr.vsync_start ||
974 old_crtc_state->vrr.vsync_end != new_crtc_state->vrr.vsync_end;
975 }
976
cmrr_params_changed(const struct intel_crtc_state * old_crtc_state,const struct intel_crtc_state * new_crtc_state)977 static bool cmrr_params_changed(const struct intel_crtc_state *old_crtc_state,
978 const struct intel_crtc_state *new_crtc_state)
979 {
980 return old_crtc_state->cmrr.cmrr_m != new_crtc_state->cmrr.cmrr_m ||
981 old_crtc_state->cmrr.cmrr_n != new_crtc_state->cmrr.cmrr_n;
982 }
983
intel_crtc_vrr_enabling(struct intel_atomic_state * state,struct intel_crtc * crtc)984 static bool intel_crtc_vrr_enabling(struct intel_atomic_state *state,
985 struct intel_crtc *crtc)
986 {
987 const struct intel_crtc_state *old_crtc_state =
988 intel_atomic_get_old_crtc_state(state, crtc);
989 const struct intel_crtc_state *new_crtc_state =
990 intel_atomic_get_new_crtc_state(state, crtc);
991
992 if (!new_crtc_state->hw.active)
993 return false;
994
995 return is_enabling(vrr.enable, old_crtc_state, new_crtc_state) ||
996 (new_crtc_state->vrr.enable &&
997 (new_crtc_state->update_m_n || new_crtc_state->update_lrr ||
998 vrr_params_changed(old_crtc_state, new_crtc_state)));
999 }
1000
intel_crtc_vrr_disabling(struct intel_atomic_state * state,struct intel_crtc * crtc)1001 bool intel_crtc_vrr_disabling(struct intel_atomic_state *state,
1002 struct intel_crtc *crtc)
1003 {
1004 const struct intel_crtc_state *old_crtc_state =
1005 intel_atomic_get_old_crtc_state(state, crtc);
1006 const struct intel_crtc_state *new_crtc_state =
1007 intel_atomic_get_new_crtc_state(state, crtc);
1008
1009 if (!old_crtc_state->hw.active)
1010 return false;
1011
1012 return is_disabling(vrr.enable, old_crtc_state, new_crtc_state) ||
1013 (old_crtc_state->vrr.enable &&
1014 (new_crtc_state->update_m_n || new_crtc_state->update_lrr ||
1015 vrr_params_changed(old_crtc_state, new_crtc_state)));
1016 }
1017
audio_enabling(const struct intel_crtc_state * old_crtc_state,const struct intel_crtc_state * new_crtc_state)1018 static bool audio_enabling(const struct intel_crtc_state *old_crtc_state,
1019 const struct intel_crtc_state *new_crtc_state)
1020 {
1021 if (!new_crtc_state->hw.active)
1022 return false;
1023
1024 return is_enabling(has_audio, old_crtc_state, new_crtc_state) ||
1025 (new_crtc_state->has_audio &&
1026 memcmp(old_crtc_state->eld, new_crtc_state->eld, MAX_ELD_BYTES) != 0);
1027 }
1028
audio_disabling(const struct intel_crtc_state * old_crtc_state,const struct intel_crtc_state * new_crtc_state)1029 static bool audio_disabling(const struct intel_crtc_state *old_crtc_state,
1030 const struct intel_crtc_state *new_crtc_state)
1031 {
1032 if (!old_crtc_state->hw.active)
1033 return false;
1034
1035 return is_disabling(has_audio, old_crtc_state, new_crtc_state) ||
1036 (old_crtc_state->has_audio &&
1037 memcmp(old_crtc_state->eld, new_crtc_state->eld, MAX_ELD_BYTES) != 0);
1038 }
1039
1040 #undef is_disabling
1041 #undef is_enabling
1042
intel_post_plane_update(struct intel_atomic_state * state,struct intel_crtc * crtc)1043 static void intel_post_plane_update(struct intel_atomic_state *state,
1044 struct intel_crtc *crtc)
1045 {
1046 struct intel_display *display = to_intel_display(state);
1047 const struct intel_crtc_state *old_crtc_state =
1048 intel_atomic_get_old_crtc_state(state, crtc);
1049 const struct intel_crtc_state *new_crtc_state =
1050 intel_atomic_get_new_crtc_state(state, crtc);
1051 enum pipe pipe = crtc->pipe;
1052
1053 intel_frontbuffer_flip(display, new_crtc_state->fb_bits);
1054
1055 if (new_crtc_state->update_wm_post && new_crtc_state->hw.active)
1056 intel_update_watermarks(display);
1057
1058 intel_fbc_post_update(state, crtc);
1059
1060 if (needs_async_flip_vtd_wa(old_crtc_state) &&
1061 !needs_async_flip_vtd_wa(new_crtc_state))
1062 intel_async_flip_vtd_wa(display, pipe, false);
1063
1064 if (needs_nv12_wa(old_crtc_state) &&
1065 !needs_nv12_wa(new_crtc_state))
1066 skl_wa_827(display, pipe, false);
1067
1068 if (needs_scalerclk_wa(old_crtc_state) &&
1069 !needs_scalerclk_wa(new_crtc_state))
1070 icl_wa_scalerclkgating(display, pipe, false);
1071
1072 if (needs_cursorclk_wa(old_crtc_state) &&
1073 !needs_cursorclk_wa(new_crtc_state))
1074 icl_wa_cursorclkgating(display, pipe, false);
1075
1076 if (intel_crtc_needs_color_update(new_crtc_state))
1077 intel_color_post_update(new_crtc_state);
1078
1079 if (audio_enabling(old_crtc_state, new_crtc_state))
1080 intel_encoders_audio_enable(state, crtc);
1081
1082 intel_alpm_post_plane_update(state, crtc);
1083
1084 intel_psr_post_plane_update(state, crtc);
1085 }
1086
intel_post_plane_update_after_readout(struct intel_atomic_state * state,struct intel_crtc * crtc)1087 static void intel_post_plane_update_after_readout(struct intel_atomic_state *state,
1088 struct intel_crtc *crtc)
1089 {
1090 const struct intel_crtc_state *new_crtc_state =
1091 intel_atomic_get_new_crtc_state(state, crtc);
1092
1093 /* Must be done after gamma readout due to HSW split gamma vs. IPS w/a */
1094 hsw_ips_post_update(state, crtc);
1095
1096 /*
1097 * Activate DRRS after state readout to avoid
1098 * dp_m_n vs. dp_m2_n2 confusion on BDW+.
1099 */
1100 intel_drrs_activate(new_crtc_state);
1101 }
1102
intel_crtc_enable_flip_done(struct intel_atomic_state * state,struct intel_crtc * crtc)1103 static void intel_crtc_enable_flip_done(struct intel_atomic_state *state,
1104 struct intel_crtc *crtc)
1105 {
1106 const struct intel_crtc_state *crtc_state =
1107 intel_atomic_get_new_crtc_state(state, crtc);
1108 u8 update_planes = crtc_state->update_planes;
1109 const struct intel_plane_state __maybe_unused *plane_state;
1110 struct intel_plane *plane;
1111 int i;
1112
1113 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
1114 if (plane->pipe == crtc->pipe &&
1115 update_planes & BIT(plane->id))
1116 plane->enable_flip_done(plane);
1117 }
1118 }
1119
intel_crtc_disable_flip_done(struct intel_atomic_state * state,struct intel_crtc * crtc)1120 static void intel_crtc_disable_flip_done(struct intel_atomic_state *state,
1121 struct intel_crtc *crtc)
1122 {
1123 const struct intel_crtc_state *crtc_state =
1124 intel_atomic_get_new_crtc_state(state, crtc);
1125 u8 update_planes = crtc_state->update_planes;
1126 const struct intel_plane_state __maybe_unused *plane_state;
1127 struct intel_plane *plane;
1128 int i;
1129
1130 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
1131 if (plane->pipe == crtc->pipe &&
1132 update_planes & BIT(plane->id))
1133 plane->disable_flip_done(plane);
1134 }
1135 }
1136
intel_crtc_async_flip_disable_wa(struct intel_atomic_state * state,struct intel_crtc * crtc)1137 static void intel_crtc_async_flip_disable_wa(struct intel_atomic_state *state,
1138 struct intel_crtc *crtc)
1139 {
1140 const struct intel_crtc_state *old_crtc_state =
1141 intel_atomic_get_old_crtc_state(state, crtc);
1142 const struct intel_crtc_state *new_crtc_state =
1143 intel_atomic_get_new_crtc_state(state, crtc);
1144 u8 disable_async_flip_planes = old_crtc_state->async_flip_planes &
1145 ~new_crtc_state->async_flip_planes;
1146 const struct intel_plane_state *old_plane_state;
1147 struct intel_plane *plane;
1148 bool need_vbl_wait = false;
1149 int i;
1150
1151 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
1152 if (plane->need_async_flip_toggle_wa &&
1153 plane->pipe == crtc->pipe &&
1154 disable_async_flip_planes & BIT(plane->id)) {
1155 /*
1156 * Apart from the async flip bit we want to
1157 * preserve the old state for the plane.
1158 */
1159 intel_plane_async_flip(NULL, plane,
1160 old_crtc_state, old_plane_state, false);
1161 need_vbl_wait = true;
1162 }
1163 }
1164
1165 if (need_vbl_wait)
1166 intel_crtc_wait_for_next_vblank(crtc);
1167 }
1168
intel_pre_plane_update(struct intel_atomic_state * state,struct intel_crtc * crtc)1169 static void intel_pre_plane_update(struct intel_atomic_state *state,
1170 struct intel_crtc *crtc)
1171 {
1172 struct intel_display *display = to_intel_display(state);
1173 const struct intel_crtc_state *old_crtc_state =
1174 intel_atomic_get_old_crtc_state(state, crtc);
1175 const struct intel_crtc_state *new_crtc_state =
1176 intel_atomic_get_new_crtc_state(state, crtc);
1177 enum pipe pipe = crtc->pipe;
1178
1179 intel_alpm_pre_plane_update(state, crtc);
1180 intel_psr_pre_plane_update(state, crtc);
1181
1182 if (intel_crtc_vrr_disabling(state, crtc)) {
1183 intel_vrr_disable(old_crtc_state);
1184 intel_crtc_update_active_timings(old_crtc_state, false);
1185 }
1186
1187 if (audio_disabling(old_crtc_state, new_crtc_state))
1188 intel_encoders_audio_disable(state, crtc);
1189
1190 intel_drrs_deactivate(old_crtc_state);
1191
1192 if (hsw_ips_pre_update(state, crtc))
1193 intel_crtc_wait_for_next_vblank(crtc);
1194
1195 if (intel_fbc_pre_update(state, crtc))
1196 intel_crtc_wait_for_next_vblank(crtc);
1197
1198 if (!needs_async_flip_vtd_wa(old_crtc_state) &&
1199 needs_async_flip_vtd_wa(new_crtc_state))
1200 intel_async_flip_vtd_wa(display, pipe, true);
1201
1202 /* Display WA 827 */
1203 if (!needs_nv12_wa(old_crtc_state) &&
1204 needs_nv12_wa(new_crtc_state))
1205 skl_wa_827(display, pipe, true);
1206
1207 /* Wa_2006604312:icl,ehl */
1208 if (!needs_scalerclk_wa(old_crtc_state) &&
1209 needs_scalerclk_wa(new_crtc_state))
1210 icl_wa_scalerclkgating(display, pipe, true);
1211
1212 /* Wa_1604331009:icl,jsl,ehl */
1213 if (!needs_cursorclk_wa(old_crtc_state) &&
1214 needs_cursorclk_wa(new_crtc_state))
1215 icl_wa_cursorclkgating(display, pipe, true);
1216
1217 /*
1218 * Vblank time updates from the shadow to live plane control register
1219 * are blocked if the memory self-refresh mode is active at that
1220 * moment. So to make sure the plane gets truly disabled, disable
1221 * first the self-refresh mode. The self-refresh enable bit in turn
1222 * will be checked/applied by the HW only at the next frame start
1223 * event which is after the vblank start event, so we need to have a
1224 * wait-for-vblank between disabling the plane and the pipe.
1225 */
1226 if (HAS_GMCH(display) && old_crtc_state->hw.active &&
1227 new_crtc_state->disable_cxsr && intel_set_memory_cxsr(display, false))
1228 intel_crtc_wait_for_next_vblank(crtc);
1229
1230 /*
1231 * IVB workaround: must disable low power watermarks for at least
1232 * one frame before enabling scaling. LP watermarks can be re-enabled
1233 * when scaling is disabled.
1234 *
1235 * WaCxSRDisabledForSpriteScaling:ivb
1236 */
1237 if (!HAS_GMCH(display) && old_crtc_state->hw.active &&
1238 new_crtc_state->disable_cxsr && ilk_disable_cxsr(display))
1239 intel_crtc_wait_for_next_vblank(crtc);
1240
1241 /*
1242 * If we're doing a modeset we don't need to do any
1243 * pre-vblank watermark programming here.
1244 */
1245 if (!intel_crtc_needs_modeset(new_crtc_state)) {
1246 /*
1247 * For platforms that support atomic watermarks, program the
1248 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
1249 * will be the intermediate values that are safe for both pre- and
1250 * post- vblank; when vblank happens, the 'active' values will be set
1251 * to the final 'target' values and we'll do this again to get the
1252 * optimal watermarks. For gen9+ platforms, the values we program here
1253 * will be the final target values which will get automatically latched
1254 * at vblank time; no further programming will be necessary.
1255 *
1256 * If a platform hasn't been transitioned to atomic watermarks yet,
1257 * we'll continue to update watermarks the old way, if flags tell
1258 * us to.
1259 */
1260 if (!intel_initial_watermarks(state, crtc))
1261 if (new_crtc_state->update_wm_pre)
1262 intel_update_watermarks(display);
1263 }
1264
1265 /*
1266 * Gen2 reports pipe underruns whenever all planes are disabled.
1267 * So disable underrun reporting before all the planes get disabled.
1268 *
1269 * We do this after .initial_watermarks() so that we have a
1270 * chance of catching underruns with the intermediate watermarks
1271 * vs. the old plane configuration.
1272 */
1273 if (DISPLAY_VER(display) == 2 && planes_disabling(old_crtc_state, new_crtc_state))
1274 intel_set_cpu_fifo_underrun_reporting(display, pipe, false);
1275
1276 /*
1277 * WA for platforms where async address update enable bit
1278 * is double buffered and only latched at start of vblank.
1279 */
1280 if (old_crtc_state->async_flip_planes & ~new_crtc_state->async_flip_planes)
1281 intel_crtc_async_flip_disable_wa(state, crtc);
1282 }
1283
intel_crtc_disable_planes(struct intel_atomic_state * state,struct intel_crtc * crtc)1284 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
1285 struct intel_crtc *crtc)
1286 {
1287 struct intel_display *display = to_intel_display(state);
1288 const struct intel_crtc_state *new_crtc_state =
1289 intel_atomic_get_new_crtc_state(state, crtc);
1290 unsigned int update_mask = new_crtc_state->update_planes;
1291 const struct intel_plane_state *old_plane_state;
1292 struct intel_plane *plane;
1293 unsigned fb_bits = 0;
1294 int i;
1295
1296 intel_crtc_dpms_overlay_disable(crtc);
1297
1298 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
1299 if (crtc->pipe != plane->pipe ||
1300 !(update_mask & BIT(plane->id)))
1301 continue;
1302
1303 intel_plane_disable_arm(NULL, plane, new_crtc_state);
1304
1305 if (old_plane_state->uapi.visible)
1306 fb_bits |= plane->frontbuffer_bit;
1307 }
1308
1309 intel_frontbuffer_flip(display, fb_bits);
1310 }
1311
intel_encoders_update_prepare(struct intel_atomic_state * state)1312 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
1313 {
1314 struct intel_display *display = to_intel_display(state);
1315 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
1316 struct intel_crtc *crtc;
1317 int i;
1318
1319 /*
1320 * Make sure the DPLL state is up-to-date for fastset TypeC ports after non-blocking commits.
1321 * TODO: Update the DPLL state for all cases in the encoder->update_prepare() hook.
1322 */
1323 if (display->dpll.mgr) {
1324 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
1325 if (intel_crtc_needs_modeset(new_crtc_state))
1326 continue;
1327
1328 new_crtc_state->shared_dpll = old_crtc_state->shared_dpll;
1329 new_crtc_state->dpll_hw_state = old_crtc_state->dpll_hw_state;
1330 }
1331 }
1332 }
1333
intel_encoders_pre_pll_enable(struct intel_atomic_state * state,struct intel_crtc * crtc)1334 static void intel_encoders_pre_pll_enable(struct intel_atomic_state *state,
1335 struct intel_crtc *crtc)
1336 {
1337 const struct intel_crtc_state *crtc_state =
1338 intel_atomic_get_new_crtc_state(state, crtc);
1339 const struct drm_connector_state *conn_state;
1340 struct drm_connector *conn;
1341 int i;
1342
1343 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1344 struct intel_encoder *encoder =
1345 to_intel_encoder(conn_state->best_encoder);
1346
1347 if (conn_state->crtc != &crtc->base)
1348 continue;
1349
1350 if (encoder->pre_pll_enable)
1351 encoder->pre_pll_enable(state, encoder,
1352 crtc_state, conn_state);
1353 }
1354 }
1355
intel_encoders_pre_enable(struct intel_atomic_state * state,struct intel_crtc * crtc)1356 static void intel_encoders_pre_enable(struct intel_atomic_state *state,
1357 struct intel_crtc *crtc)
1358 {
1359 const struct intel_crtc_state *crtc_state =
1360 intel_atomic_get_new_crtc_state(state, crtc);
1361 const struct drm_connector_state *conn_state;
1362 struct drm_connector *conn;
1363 int i;
1364
1365 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1366 struct intel_encoder *encoder =
1367 to_intel_encoder(conn_state->best_encoder);
1368
1369 if (conn_state->crtc != &crtc->base)
1370 continue;
1371
1372 if (encoder->pre_enable)
1373 encoder->pre_enable(state, encoder,
1374 crtc_state, conn_state);
1375 }
1376 }
1377
intel_encoders_enable(struct intel_atomic_state * state,struct intel_crtc * crtc)1378 static void intel_encoders_enable(struct intel_atomic_state *state,
1379 struct intel_crtc *crtc)
1380 {
1381 const struct intel_crtc_state *crtc_state =
1382 intel_atomic_get_new_crtc_state(state, crtc);
1383 const struct drm_connector_state *conn_state;
1384 struct drm_connector *conn;
1385 int i;
1386
1387 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1388 struct intel_encoder *encoder =
1389 to_intel_encoder(conn_state->best_encoder);
1390
1391 if (conn_state->crtc != &crtc->base)
1392 continue;
1393
1394 if (encoder->enable)
1395 encoder->enable(state, encoder,
1396 crtc_state, conn_state);
1397 intel_opregion_notify_encoder(encoder, true);
1398 }
1399 }
1400
intel_encoders_disable(struct intel_atomic_state * state,struct intel_crtc * crtc)1401 static void intel_encoders_disable(struct intel_atomic_state *state,
1402 struct intel_crtc *crtc)
1403 {
1404 const struct intel_crtc_state *old_crtc_state =
1405 intel_atomic_get_old_crtc_state(state, crtc);
1406 const struct drm_connector_state *old_conn_state;
1407 struct drm_connector *conn;
1408 int i;
1409
1410 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1411 struct intel_encoder *encoder =
1412 to_intel_encoder(old_conn_state->best_encoder);
1413
1414 if (old_conn_state->crtc != &crtc->base)
1415 continue;
1416
1417 intel_opregion_notify_encoder(encoder, false);
1418 if (encoder->disable)
1419 encoder->disable(state, encoder,
1420 old_crtc_state, old_conn_state);
1421 }
1422 }
1423
intel_encoders_post_disable(struct intel_atomic_state * state,struct intel_crtc * crtc)1424 static void intel_encoders_post_disable(struct intel_atomic_state *state,
1425 struct intel_crtc *crtc)
1426 {
1427 const struct intel_crtc_state *old_crtc_state =
1428 intel_atomic_get_old_crtc_state(state, crtc);
1429 const struct drm_connector_state *old_conn_state;
1430 struct drm_connector *conn;
1431 int i;
1432
1433 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1434 struct intel_encoder *encoder =
1435 to_intel_encoder(old_conn_state->best_encoder);
1436
1437 if (old_conn_state->crtc != &crtc->base)
1438 continue;
1439
1440 if (encoder->post_disable)
1441 encoder->post_disable(state, encoder,
1442 old_crtc_state, old_conn_state);
1443 }
1444 }
1445
intel_encoders_post_pll_disable(struct intel_atomic_state * state,struct intel_crtc * crtc)1446 static void intel_encoders_post_pll_disable(struct intel_atomic_state *state,
1447 struct intel_crtc *crtc)
1448 {
1449 const struct intel_crtc_state *old_crtc_state =
1450 intel_atomic_get_old_crtc_state(state, crtc);
1451 const struct drm_connector_state *old_conn_state;
1452 struct drm_connector *conn;
1453 int i;
1454
1455 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1456 struct intel_encoder *encoder =
1457 to_intel_encoder(old_conn_state->best_encoder);
1458
1459 if (old_conn_state->crtc != &crtc->base)
1460 continue;
1461
1462 if (encoder->post_pll_disable)
1463 encoder->post_pll_disable(state, encoder,
1464 old_crtc_state, old_conn_state);
1465 }
1466 }
1467
intel_encoders_update_pipe(struct intel_atomic_state * state,struct intel_crtc * crtc)1468 static void intel_encoders_update_pipe(struct intel_atomic_state *state,
1469 struct intel_crtc *crtc)
1470 {
1471 const struct intel_crtc_state *crtc_state =
1472 intel_atomic_get_new_crtc_state(state, crtc);
1473 const struct drm_connector_state *conn_state;
1474 struct drm_connector *conn;
1475 int i;
1476
1477 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1478 struct intel_encoder *encoder =
1479 to_intel_encoder(conn_state->best_encoder);
1480
1481 if (conn_state->crtc != &crtc->base)
1482 continue;
1483
1484 if (encoder->update_pipe)
1485 encoder->update_pipe(state, encoder,
1486 crtc_state, conn_state);
1487 }
1488 }
1489
ilk_configure_cpu_transcoder(const struct intel_crtc_state * crtc_state)1490 static void ilk_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
1491 {
1492 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1493 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1494
1495 if (crtc_state->has_pch_encoder) {
1496 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1497 &crtc_state->fdi_m_n);
1498 } else if (intel_crtc_has_dp_encoder(crtc_state)) {
1499 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1500 &crtc_state->dp_m_n);
1501 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
1502 &crtc_state->dp_m2_n2);
1503 }
1504
1505 intel_set_transcoder_timings(crtc_state);
1506
1507 ilk_set_pipeconf(crtc_state);
1508 }
1509
ilk_crtc_enable(struct intel_atomic_state * state,struct intel_crtc * crtc)1510 static void ilk_crtc_enable(struct intel_atomic_state *state,
1511 struct intel_crtc *crtc)
1512 {
1513 struct intel_display *display = to_intel_display(crtc);
1514 const struct intel_crtc_state *new_crtc_state =
1515 intel_atomic_get_new_crtc_state(state, crtc);
1516 enum pipe pipe = crtc->pipe;
1517
1518 if (drm_WARN_ON(display->drm, crtc->active))
1519 return;
1520
1521 /*
1522 * Sometimes spurious CPU pipe underruns happen during FDI
1523 * training, at least with VGA+HDMI cloning. Suppress them.
1524 *
1525 * On ILK we get an occasional spurious CPU pipe underruns
1526 * between eDP port A enable and vdd enable. Also PCH port
1527 * enable seems to result in the occasional CPU pipe underrun.
1528 *
1529 * Spurious PCH underruns also occur during PCH enabling.
1530 */
1531 intel_set_cpu_fifo_underrun_reporting(display, pipe, false);
1532 intel_set_pch_fifo_underrun_reporting(display, pipe, false);
1533
1534 ilk_configure_cpu_transcoder(new_crtc_state);
1535
1536 intel_set_pipe_src_size(new_crtc_state);
1537
1538 crtc->active = true;
1539
1540 intel_encoders_pre_enable(state, crtc);
1541
1542 if (new_crtc_state->has_pch_encoder) {
1543 ilk_pch_pre_enable(state, crtc);
1544 } else {
1545 assert_fdi_tx_disabled(display, pipe);
1546 assert_fdi_rx_disabled(display, pipe);
1547 }
1548
1549 ilk_pfit_enable(new_crtc_state);
1550
1551 /*
1552 * On ILK+ LUT must be loaded before the pipe is running but with
1553 * clocks enabled
1554 */
1555 intel_color_modeset(new_crtc_state);
1556
1557 intel_initial_watermarks(state, crtc);
1558 intel_enable_transcoder(new_crtc_state);
1559
1560 if (new_crtc_state->has_pch_encoder)
1561 ilk_pch_enable(state, crtc);
1562
1563 intel_crtc_vblank_on(new_crtc_state);
1564
1565 intel_encoders_enable(state, crtc);
1566
1567 if (HAS_PCH_CPT(display))
1568 intel_wait_for_pipe_scanline_moving(crtc);
1569
1570 /*
1571 * Must wait for vblank to avoid spurious PCH FIFO underruns.
1572 * And a second vblank wait is needed at least on ILK with
1573 * some interlaced HDMI modes. Let's do the double wait always
1574 * in case there are more corner cases we don't know about.
1575 */
1576 if (new_crtc_state->has_pch_encoder) {
1577 intel_crtc_wait_for_next_vblank(crtc);
1578 intel_crtc_wait_for_next_vblank(crtc);
1579 }
1580 intel_set_cpu_fifo_underrun_reporting(display, pipe, true);
1581 intel_set_pch_fifo_underrun_reporting(display, pipe, true);
1582 }
1583
1584 /* Display WA #1180: WaDisableScalarClockGating: glk */
glk_need_scaler_clock_gating_wa(const struct intel_crtc_state * crtc_state)1585 static bool glk_need_scaler_clock_gating_wa(const struct intel_crtc_state *crtc_state)
1586 {
1587 struct intel_display *display = to_intel_display(crtc_state);
1588
1589 return DISPLAY_VER(display) == 10 && crtc_state->pch_pfit.enabled;
1590 }
1591
glk_pipe_scaler_clock_gating_wa(struct intel_crtc * crtc,bool enable)1592 static void glk_pipe_scaler_clock_gating_wa(struct intel_crtc *crtc, bool enable)
1593 {
1594 struct intel_display *display = to_intel_display(crtc);
1595 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
1596
1597 intel_de_rmw(display, CLKGATE_DIS_PSL(crtc->pipe),
1598 mask, enable ? mask : 0);
1599 }
1600
hsw_set_linetime_wm(const struct intel_crtc_state * crtc_state)1601 static void hsw_set_linetime_wm(const struct intel_crtc_state *crtc_state)
1602 {
1603 struct intel_display *display = to_intel_display(crtc_state);
1604 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1605
1606 intel_de_write(display, WM_LINETIME(crtc->pipe),
1607 HSW_LINETIME(crtc_state->linetime) |
1608 HSW_IPS_LINETIME(crtc_state->ips_linetime));
1609 }
1610
hsw_set_frame_start_delay(const struct intel_crtc_state * crtc_state)1611 static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state)
1612 {
1613 struct intel_display *display = to_intel_display(crtc_state);
1614
1615 intel_de_rmw(display, CHICKEN_TRANS(display, crtc_state->cpu_transcoder),
1616 HSW_FRAME_START_DELAY_MASK,
1617 HSW_FRAME_START_DELAY(crtc_state->framestart_delay - 1));
1618 }
1619
hsw_configure_cpu_transcoder(const struct intel_crtc_state * crtc_state)1620 static void hsw_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
1621 {
1622 struct intel_display *display = to_intel_display(crtc_state);
1623 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1624 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1625
1626 if (crtc_state->has_pch_encoder) {
1627 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1628 &crtc_state->fdi_m_n);
1629 } else if (intel_crtc_has_dp_encoder(crtc_state)) {
1630 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1631 &crtc_state->dp_m_n);
1632 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
1633 &crtc_state->dp_m2_n2);
1634 }
1635
1636 intel_set_transcoder_timings(crtc_state);
1637 if (HAS_VRR(display))
1638 intel_vrr_set_transcoder_timings(crtc_state);
1639
1640 if (cpu_transcoder != TRANSCODER_EDP)
1641 intel_de_write(display, TRANS_MULT(display, cpu_transcoder),
1642 crtc_state->pixel_multiplier - 1);
1643
1644 hsw_set_frame_start_delay(crtc_state);
1645
1646 hsw_set_transconf(crtc_state);
1647 }
1648
hsw_crtc_enable(struct intel_atomic_state * state,struct intel_crtc * crtc)1649 static void hsw_crtc_enable(struct intel_atomic_state *state,
1650 struct intel_crtc *crtc)
1651 {
1652 struct intel_display *display = to_intel_display(state);
1653 const struct intel_crtc_state *new_crtc_state =
1654 intel_atomic_get_new_crtc_state(state, crtc);
1655 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1656 struct intel_crtc *pipe_crtc;
1657 int i;
1658
1659 if (drm_WARN_ON(display->drm, crtc->active))
1660 return;
1661 for_each_pipe_crtc_modeset_enable(display, pipe_crtc, new_crtc_state, i)
1662 intel_dmc_enable_pipe(display, pipe_crtc->pipe);
1663
1664 intel_encoders_pre_pll_enable(state, crtc);
1665
1666 if (new_crtc_state->shared_dpll)
1667 intel_enable_shared_dpll(new_crtc_state);
1668
1669 intel_encoders_pre_enable(state, crtc);
1670
1671 for_each_pipe_crtc_modeset_enable(display, pipe_crtc, new_crtc_state, i) {
1672 const struct intel_crtc_state *pipe_crtc_state =
1673 intel_atomic_get_new_crtc_state(state, pipe_crtc);
1674
1675 intel_dsc_enable(pipe_crtc_state);
1676
1677 if (HAS_UNCOMPRESSED_JOINER(display))
1678 intel_uncompressed_joiner_enable(pipe_crtc_state);
1679
1680 intel_set_pipe_src_size(pipe_crtc_state);
1681
1682 if (DISPLAY_VER(display) >= 9 || display->platform.broadwell)
1683 bdw_set_pipe_misc(NULL, pipe_crtc_state);
1684 }
1685
1686 if (!transcoder_is_dsi(cpu_transcoder))
1687 hsw_configure_cpu_transcoder(new_crtc_state);
1688
1689 for_each_pipe_crtc_modeset_enable(display, pipe_crtc, new_crtc_state, i) {
1690 const struct intel_crtc_state *pipe_crtc_state =
1691 intel_atomic_get_new_crtc_state(state, pipe_crtc);
1692
1693 pipe_crtc->active = true;
1694
1695 if (glk_need_scaler_clock_gating_wa(pipe_crtc_state))
1696 glk_pipe_scaler_clock_gating_wa(pipe_crtc, true);
1697
1698 if (DISPLAY_VER(display) >= 9)
1699 skl_pfit_enable(pipe_crtc_state);
1700 else
1701 ilk_pfit_enable(pipe_crtc_state);
1702
1703 /*
1704 * On ILK+ LUT must be loaded before the pipe is running but with
1705 * clocks enabled
1706 */
1707 intel_color_modeset(pipe_crtc_state);
1708
1709 hsw_set_linetime_wm(pipe_crtc_state);
1710
1711 if (DISPLAY_VER(display) >= 11)
1712 icl_set_pipe_chicken(pipe_crtc_state);
1713
1714 intel_initial_watermarks(state, pipe_crtc);
1715 }
1716
1717 intel_encoders_enable(state, crtc);
1718
1719 for_each_pipe_crtc_modeset_enable(display, pipe_crtc, new_crtc_state, i) {
1720 const struct intel_crtc_state *pipe_crtc_state =
1721 intel_atomic_get_new_crtc_state(state, pipe_crtc);
1722 enum pipe hsw_workaround_pipe;
1723
1724 if (glk_need_scaler_clock_gating_wa(pipe_crtc_state)) {
1725 intel_crtc_wait_for_next_vblank(pipe_crtc);
1726 glk_pipe_scaler_clock_gating_wa(pipe_crtc, false);
1727 }
1728
1729 /*
1730 * If we change the relative order between pipe/planes
1731 * enabling, we need to change the workaround.
1732 */
1733 hsw_workaround_pipe = pipe_crtc_state->hsw_workaround_pipe;
1734 if (display->platform.haswell && hsw_workaround_pipe != INVALID_PIPE) {
1735 struct intel_crtc *wa_crtc =
1736 intel_crtc_for_pipe(display, hsw_workaround_pipe);
1737
1738 intel_crtc_wait_for_next_vblank(wa_crtc);
1739 intel_crtc_wait_for_next_vblank(wa_crtc);
1740 }
1741 }
1742 }
1743
ilk_crtc_disable(struct intel_atomic_state * state,struct intel_crtc * crtc)1744 static void ilk_crtc_disable(struct intel_atomic_state *state,
1745 struct intel_crtc *crtc)
1746 {
1747 struct intel_display *display = to_intel_display(crtc);
1748 const struct intel_crtc_state *old_crtc_state =
1749 intel_atomic_get_old_crtc_state(state, crtc);
1750 enum pipe pipe = crtc->pipe;
1751
1752 /*
1753 * Sometimes spurious CPU pipe underruns happen when the
1754 * pipe is already disabled, but FDI RX/TX is still enabled.
1755 * Happens at least with VGA+HDMI cloning. Suppress them.
1756 */
1757 intel_set_cpu_fifo_underrun_reporting(display, pipe, false);
1758 intel_set_pch_fifo_underrun_reporting(display, pipe, false);
1759
1760 intel_encoders_disable(state, crtc);
1761
1762 intel_crtc_vblank_off(old_crtc_state);
1763
1764 intel_disable_transcoder(old_crtc_state);
1765
1766 ilk_pfit_disable(old_crtc_state);
1767
1768 if (old_crtc_state->has_pch_encoder)
1769 ilk_pch_disable(state, crtc);
1770
1771 intel_encoders_post_disable(state, crtc);
1772
1773 if (old_crtc_state->has_pch_encoder)
1774 ilk_pch_post_disable(state, crtc);
1775
1776 intel_set_cpu_fifo_underrun_reporting(display, pipe, true);
1777 intel_set_pch_fifo_underrun_reporting(display, pipe, true);
1778 }
1779
hsw_crtc_disable(struct intel_atomic_state * state,struct intel_crtc * crtc)1780 static void hsw_crtc_disable(struct intel_atomic_state *state,
1781 struct intel_crtc *crtc)
1782 {
1783 struct intel_display *display = to_intel_display(state);
1784 const struct intel_crtc_state *old_crtc_state =
1785 intel_atomic_get_old_crtc_state(state, crtc);
1786 struct intel_crtc *pipe_crtc;
1787 int i;
1788
1789 /*
1790 * FIXME collapse everything to one hook.
1791 * Need care with mst->ddi interactions.
1792 */
1793 intel_encoders_disable(state, crtc);
1794 intel_encoders_post_disable(state, crtc);
1795
1796 intel_disable_shared_dpll(old_crtc_state);
1797
1798 intel_encoders_post_pll_disable(state, crtc);
1799
1800 for_each_pipe_crtc_modeset_disable(display, pipe_crtc, old_crtc_state, i)
1801 intel_dmc_disable_pipe(display, pipe_crtc->pipe);
1802 }
1803
1804 /* Prefer intel_encoder_is_combo() */
intel_phy_is_combo(struct intel_display * display,enum phy phy)1805 bool intel_phy_is_combo(struct intel_display *display, enum phy phy)
1806 {
1807 if (phy == PHY_NONE)
1808 return false;
1809 else if (display->platform.alderlake_s)
1810 return phy <= PHY_E;
1811 else if (display->platform.dg1 || display->platform.rocketlake)
1812 return phy <= PHY_D;
1813 else if (display->platform.jasperlake || display->platform.elkhartlake)
1814 return phy <= PHY_C;
1815 else if (display->platform.alderlake_p || IS_DISPLAY_VER(display, 11, 12))
1816 return phy <= PHY_B;
1817 else
1818 /*
1819 * DG2 outputs labelled as "combo PHY" in the bspec use
1820 * SNPS PHYs with completely different programming,
1821 * hence we always return false here.
1822 */
1823 return false;
1824 }
1825
1826 /* Prefer intel_encoder_is_tc() */
intel_phy_is_tc(struct intel_display * display,enum phy phy)1827 bool intel_phy_is_tc(struct intel_display *display, enum phy phy)
1828 {
1829 /*
1830 * Discrete GPU phy's are not attached to FIA's to support TC
1831 * subsystem Legacy or non-legacy, and only support native DP/HDMI
1832 */
1833 if (display->platform.dgfx)
1834 return false;
1835
1836 if (DISPLAY_VER(display) >= 13)
1837 return phy >= PHY_F && phy <= PHY_I;
1838 else if (display->platform.tigerlake)
1839 return phy >= PHY_D && phy <= PHY_I;
1840 else if (display->platform.icelake)
1841 return phy >= PHY_C && phy <= PHY_F;
1842
1843 return false;
1844 }
1845
1846 /* Prefer intel_encoder_is_snps() */
intel_phy_is_snps(struct intel_display * display,enum phy phy)1847 bool intel_phy_is_snps(struct intel_display *display, enum phy phy)
1848 {
1849 /*
1850 * For DG2, and for DG2 only, all four "combo" ports and the TC1 port
1851 * (PHY E) use Synopsis PHYs. See intel_phy_is_tc().
1852 */
1853 return display->platform.dg2 && phy > PHY_NONE && phy <= PHY_E;
1854 }
1855
1856 /* Prefer intel_encoder_to_phy() */
intel_port_to_phy(struct intel_display * display,enum port port)1857 enum phy intel_port_to_phy(struct intel_display *display, enum port port)
1858 {
1859 if (DISPLAY_VER(display) >= 13 && port >= PORT_D_XELPD)
1860 return PHY_D + port - PORT_D_XELPD;
1861 else if (DISPLAY_VER(display) >= 13 && port >= PORT_TC1)
1862 return PHY_F + port - PORT_TC1;
1863 else if (display->platform.alderlake_s && port >= PORT_TC1)
1864 return PHY_B + port - PORT_TC1;
1865 else if ((display->platform.dg1 || display->platform.rocketlake) && port >= PORT_TC1)
1866 return PHY_C + port - PORT_TC1;
1867 else if ((display->platform.jasperlake || display->platform.elkhartlake) &&
1868 port == PORT_D)
1869 return PHY_A;
1870
1871 return PHY_A + port - PORT_A;
1872 }
1873
1874 /* Prefer intel_encoder_to_tc() */
intel_port_to_tc(struct intel_display * display,enum port port)1875 enum tc_port intel_port_to_tc(struct intel_display *display, enum port port)
1876 {
1877 if (!intel_phy_is_tc(display, intel_port_to_phy(display, port)))
1878 return TC_PORT_NONE;
1879
1880 if (DISPLAY_VER(display) >= 12)
1881 return TC_PORT_1 + port - PORT_TC1;
1882 else
1883 return TC_PORT_1 + port - PORT_C;
1884 }
1885
intel_encoder_to_phy(struct intel_encoder * encoder)1886 enum phy intel_encoder_to_phy(struct intel_encoder *encoder)
1887 {
1888 struct intel_display *display = to_intel_display(encoder);
1889
1890 return intel_port_to_phy(display, encoder->port);
1891 }
1892
intel_encoder_is_combo(struct intel_encoder * encoder)1893 bool intel_encoder_is_combo(struct intel_encoder *encoder)
1894 {
1895 struct intel_display *display = to_intel_display(encoder);
1896
1897 return intel_phy_is_combo(display, intel_encoder_to_phy(encoder));
1898 }
1899
intel_encoder_is_snps(struct intel_encoder * encoder)1900 bool intel_encoder_is_snps(struct intel_encoder *encoder)
1901 {
1902 struct intel_display *display = to_intel_display(encoder);
1903
1904 return intel_phy_is_snps(display, intel_encoder_to_phy(encoder));
1905 }
1906
intel_encoder_is_tc(struct intel_encoder * encoder)1907 bool intel_encoder_is_tc(struct intel_encoder *encoder)
1908 {
1909 struct intel_display *display = to_intel_display(encoder);
1910
1911 return intel_phy_is_tc(display, intel_encoder_to_phy(encoder));
1912 }
1913
intel_encoder_to_tc(struct intel_encoder * encoder)1914 enum tc_port intel_encoder_to_tc(struct intel_encoder *encoder)
1915 {
1916 struct intel_display *display = to_intel_display(encoder);
1917
1918 return intel_port_to_tc(display, encoder->port);
1919 }
1920
1921 enum intel_display_power_domain
intel_aux_power_domain(struct intel_digital_port * dig_port)1922 intel_aux_power_domain(struct intel_digital_port *dig_port)
1923 {
1924 struct intel_display *display = to_intel_display(dig_port);
1925
1926 if (intel_tc_port_in_tbt_alt_mode(dig_port))
1927 return intel_display_power_tbt_aux_domain(display, dig_port->aux_ch);
1928
1929 return intel_display_power_legacy_aux_domain(display, dig_port->aux_ch);
1930 }
1931
get_crtc_power_domains(struct intel_crtc_state * crtc_state,struct intel_power_domain_mask * mask)1932 static void get_crtc_power_domains(struct intel_crtc_state *crtc_state,
1933 struct intel_power_domain_mask *mask)
1934 {
1935 struct intel_display *display = to_intel_display(crtc_state);
1936 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1937 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1938 struct drm_encoder *encoder;
1939 enum pipe pipe = crtc->pipe;
1940
1941 bitmap_zero(mask->bits, POWER_DOMAIN_NUM);
1942
1943 if (!crtc_state->hw.active)
1944 return;
1945
1946 set_bit(POWER_DOMAIN_PIPE(pipe), mask->bits);
1947 set_bit(POWER_DOMAIN_TRANSCODER(cpu_transcoder), mask->bits);
1948 if (crtc_state->pch_pfit.enabled ||
1949 crtc_state->pch_pfit.force_thru)
1950 set_bit(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe), mask->bits);
1951
1952 drm_for_each_encoder_mask(encoder, display->drm,
1953 crtc_state->uapi.encoder_mask) {
1954 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
1955
1956 set_bit(intel_encoder->power_domain, mask->bits);
1957 }
1958
1959 if (HAS_DDI(display) && crtc_state->has_audio)
1960 set_bit(POWER_DOMAIN_AUDIO_MMIO, mask->bits);
1961
1962 if (crtc_state->shared_dpll)
1963 set_bit(POWER_DOMAIN_DISPLAY_CORE, mask->bits);
1964
1965 if (crtc_state->dsc.compression_enable)
1966 set_bit(intel_dsc_power_domain(crtc, cpu_transcoder), mask->bits);
1967 }
1968
intel_modeset_get_crtc_power_domains(struct intel_crtc_state * crtc_state,struct intel_power_domain_mask * old_domains)1969 void intel_modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state,
1970 struct intel_power_domain_mask *old_domains)
1971 {
1972 struct intel_display *display = to_intel_display(crtc_state);
1973 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1974 enum intel_display_power_domain domain;
1975 struct intel_power_domain_mask domains, new_domains;
1976
1977 get_crtc_power_domains(crtc_state, &domains);
1978
1979 bitmap_andnot(new_domains.bits,
1980 domains.bits,
1981 crtc->enabled_power_domains.mask.bits,
1982 POWER_DOMAIN_NUM);
1983 bitmap_andnot(old_domains->bits,
1984 crtc->enabled_power_domains.mask.bits,
1985 domains.bits,
1986 POWER_DOMAIN_NUM);
1987
1988 for_each_power_domain(domain, &new_domains)
1989 intel_display_power_get_in_set(display,
1990 &crtc->enabled_power_domains,
1991 domain);
1992 }
1993
intel_modeset_put_crtc_power_domains(struct intel_crtc * crtc,struct intel_power_domain_mask * domains)1994 void intel_modeset_put_crtc_power_domains(struct intel_crtc *crtc,
1995 struct intel_power_domain_mask *domains)
1996 {
1997 struct intel_display *display = to_intel_display(crtc);
1998
1999 intel_display_power_put_mask_in_set(display,
2000 &crtc->enabled_power_domains,
2001 domains);
2002 }
2003
i9xx_configure_cpu_transcoder(const struct intel_crtc_state * crtc_state)2004 static void i9xx_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
2005 {
2006 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2007 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2008
2009 if (intel_crtc_has_dp_encoder(crtc_state)) {
2010 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
2011 &crtc_state->dp_m_n);
2012 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
2013 &crtc_state->dp_m2_n2);
2014 }
2015
2016 intel_set_transcoder_timings(crtc_state);
2017
2018 i9xx_set_pipeconf(crtc_state);
2019 }
2020
valleyview_crtc_enable(struct intel_atomic_state * state,struct intel_crtc * crtc)2021 static void valleyview_crtc_enable(struct intel_atomic_state *state,
2022 struct intel_crtc *crtc)
2023 {
2024 struct intel_display *display = to_intel_display(crtc);
2025 const struct intel_crtc_state *new_crtc_state =
2026 intel_atomic_get_new_crtc_state(state, crtc);
2027 enum pipe pipe = crtc->pipe;
2028
2029 if (drm_WARN_ON(display->drm, crtc->active))
2030 return;
2031
2032 i9xx_configure_cpu_transcoder(new_crtc_state);
2033
2034 intel_set_pipe_src_size(new_crtc_state);
2035
2036 intel_de_write(display, VLV_PIPE_MSA_MISC(display, pipe), 0);
2037
2038 if (display->platform.cherryview && pipe == PIPE_B) {
2039 intel_de_write(display, CHV_BLEND(display, pipe),
2040 CHV_BLEND_LEGACY);
2041 intel_de_write(display, CHV_CANVAS(display, pipe), 0);
2042 }
2043
2044 crtc->active = true;
2045
2046 intel_set_cpu_fifo_underrun_reporting(display, pipe, true);
2047
2048 intel_encoders_pre_pll_enable(state, crtc);
2049
2050 if (display->platform.cherryview)
2051 chv_enable_pll(new_crtc_state);
2052 else
2053 vlv_enable_pll(new_crtc_state);
2054
2055 intel_encoders_pre_enable(state, crtc);
2056
2057 i9xx_pfit_enable(new_crtc_state);
2058
2059 intel_color_modeset(new_crtc_state);
2060
2061 intel_initial_watermarks(state, crtc);
2062 intel_enable_transcoder(new_crtc_state);
2063
2064 intel_crtc_vblank_on(new_crtc_state);
2065
2066 intel_encoders_enable(state, crtc);
2067 }
2068
i9xx_crtc_enable(struct intel_atomic_state * state,struct intel_crtc * crtc)2069 static void i9xx_crtc_enable(struct intel_atomic_state *state,
2070 struct intel_crtc *crtc)
2071 {
2072 struct intel_display *display = to_intel_display(crtc);
2073 const struct intel_crtc_state *new_crtc_state =
2074 intel_atomic_get_new_crtc_state(state, crtc);
2075 enum pipe pipe = crtc->pipe;
2076
2077 if (drm_WARN_ON(display->drm, crtc->active))
2078 return;
2079
2080 i9xx_configure_cpu_transcoder(new_crtc_state);
2081
2082 intel_set_pipe_src_size(new_crtc_state);
2083
2084 crtc->active = true;
2085
2086 if (DISPLAY_VER(display) != 2)
2087 intel_set_cpu_fifo_underrun_reporting(display, pipe, true);
2088
2089 intel_encoders_pre_enable(state, crtc);
2090
2091 i9xx_enable_pll(new_crtc_state);
2092
2093 i9xx_pfit_enable(new_crtc_state);
2094
2095 intel_color_modeset(new_crtc_state);
2096
2097 if (!intel_initial_watermarks(state, crtc))
2098 intel_update_watermarks(display);
2099 intel_enable_transcoder(new_crtc_state);
2100
2101 intel_crtc_vblank_on(new_crtc_state);
2102
2103 intel_encoders_enable(state, crtc);
2104
2105 /* prevents spurious underruns */
2106 if (DISPLAY_VER(display) == 2)
2107 intel_crtc_wait_for_next_vblank(crtc);
2108 }
2109
i9xx_crtc_disable(struct intel_atomic_state * state,struct intel_crtc * crtc)2110 static void i9xx_crtc_disable(struct intel_atomic_state *state,
2111 struct intel_crtc *crtc)
2112 {
2113 struct intel_display *display = to_intel_display(state);
2114 struct intel_crtc_state *old_crtc_state =
2115 intel_atomic_get_old_crtc_state(state, crtc);
2116 enum pipe pipe = crtc->pipe;
2117
2118 /*
2119 * On gen2 planes are double buffered but the pipe isn't, so we must
2120 * wait for planes to fully turn off before disabling the pipe.
2121 */
2122 if (DISPLAY_VER(display) == 2)
2123 intel_crtc_wait_for_next_vblank(crtc);
2124
2125 intel_encoders_disable(state, crtc);
2126
2127 intel_crtc_vblank_off(old_crtc_state);
2128
2129 intel_disable_transcoder(old_crtc_state);
2130
2131 i9xx_pfit_disable(old_crtc_state);
2132
2133 intel_encoders_post_disable(state, crtc);
2134
2135 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
2136 if (display->platform.cherryview)
2137 chv_disable_pll(display, pipe);
2138 else if (display->platform.valleyview)
2139 vlv_disable_pll(display, pipe);
2140 else
2141 i9xx_disable_pll(old_crtc_state);
2142 }
2143
2144 intel_encoders_post_pll_disable(state, crtc);
2145
2146 if (DISPLAY_VER(display) != 2)
2147 intel_set_cpu_fifo_underrun_reporting(display, pipe, false);
2148
2149 if (!display->funcs.wm->initial_watermarks)
2150 intel_update_watermarks(display);
2151
2152 /* clock the pipe down to 640x480@60 to potentially save power */
2153 if (display->platform.i830)
2154 i830_enable_pipe(display, pipe);
2155 }
2156
intel_encoder_destroy(struct drm_encoder * encoder)2157 void intel_encoder_destroy(struct drm_encoder *encoder)
2158 {
2159 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
2160
2161 drm_encoder_cleanup(encoder);
2162 kfree(intel_encoder);
2163 }
2164
intel_crtc_supports_double_wide(const struct intel_crtc * crtc)2165 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
2166 {
2167 struct intel_display *display = to_intel_display(crtc);
2168
2169 /* GDG double wide on either pipe, otherwise pipe A only */
2170 return HAS_DOUBLE_WIDE(display) &&
2171 (crtc->pipe == PIPE_A || display->platform.i915g);
2172 }
2173
ilk_pipe_pixel_rate(const struct intel_crtc_state * crtc_state)2174 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *crtc_state)
2175 {
2176 u32 pixel_rate = crtc_state->hw.pipe_mode.crtc_clock;
2177 struct drm_rect src;
2178
2179 /*
2180 * We only use IF-ID interlacing. If we ever use
2181 * PF-ID we'll need to adjust the pixel_rate here.
2182 */
2183
2184 if (!crtc_state->pch_pfit.enabled)
2185 return pixel_rate;
2186
2187 drm_rect_init(&src, 0, 0,
2188 drm_rect_width(&crtc_state->pipe_src) << 16,
2189 drm_rect_height(&crtc_state->pipe_src) << 16);
2190
2191 return intel_adjusted_rate(&src, &crtc_state->pch_pfit.dst,
2192 pixel_rate);
2193 }
2194
intel_mode_from_crtc_timings(struct drm_display_mode * mode,const struct drm_display_mode * timings)2195 static void intel_mode_from_crtc_timings(struct drm_display_mode *mode,
2196 const struct drm_display_mode *timings)
2197 {
2198 mode->hdisplay = timings->crtc_hdisplay;
2199 mode->htotal = timings->crtc_htotal;
2200 mode->hsync_start = timings->crtc_hsync_start;
2201 mode->hsync_end = timings->crtc_hsync_end;
2202
2203 mode->vdisplay = timings->crtc_vdisplay;
2204 mode->vtotal = timings->crtc_vtotal;
2205 mode->vsync_start = timings->crtc_vsync_start;
2206 mode->vsync_end = timings->crtc_vsync_end;
2207
2208 mode->flags = timings->flags;
2209 mode->type = DRM_MODE_TYPE_DRIVER;
2210
2211 mode->clock = timings->crtc_clock;
2212
2213 drm_mode_set_name(mode);
2214 }
2215
intel_crtc_compute_pixel_rate(struct intel_crtc_state * crtc_state)2216 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
2217 {
2218 struct intel_display *display = to_intel_display(crtc_state);
2219
2220 if (HAS_GMCH(display))
2221 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
2222 crtc_state->pixel_rate =
2223 crtc_state->hw.pipe_mode.crtc_clock;
2224 else
2225 crtc_state->pixel_rate =
2226 ilk_pipe_pixel_rate(crtc_state);
2227 }
2228
intel_joiner_adjust_timings(const struct intel_crtc_state * crtc_state,struct drm_display_mode * mode)2229 static void intel_joiner_adjust_timings(const struct intel_crtc_state *crtc_state,
2230 struct drm_display_mode *mode)
2231 {
2232 int num_pipes = intel_crtc_num_joined_pipes(crtc_state);
2233
2234 if (num_pipes == 1)
2235 return;
2236
2237 mode->crtc_clock /= num_pipes;
2238 mode->crtc_hdisplay /= num_pipes;
2239 mode->crtc_hblank_start /= num_pipes;
2240 mode->crtc_hblank_end /= num_pipes;
2241 mode->crtc_hsync_start /= num_pipes;
2242 mode->crtc_hsync_end /= num_pipes;
2243 mode->crtc_htotal /= num_pipes;
2244 }
2245
intel_splitter_adjust_timings(const struct intel_crtc_state * crtc_state,struct drm_display_mode * mode)2246 static void intel_splitter_adjust_timings(const struct intel_crtc_state *crtc_state,
2247 struct drm_display_mode *mode)
2248 {
2249 int overlap = crtc_state->splitter.pixel_overlap;
2250 int n = crtc_state->splitter.link_count;
2251
2252 if (!crtc_state->splitter.enable)
2253 return;
2254
2255 /*
2256 * eDP MSO uses segment timings from EDID for transcoder
2257 * timings, but full mode for everything else.
2258 *
2259 * h_full = (h_segment - pixel_overlap) * link_count
2260 */
2261 mode->crtc_hdisplay = (mode->crtc_hdisplay - overlap) * n;
2262 mode->crtc_hblank_start = (mode->crtc_hblank_start - overlap) * n;
2263 mode->crtc_hblank_end = (mode->crtc_hblank_end - overlap) * n;
2264 mode->crtc_hsync_start = (mode->crtc_hsync_start - overlap) * n;
2265 mode->crtc_hsync_end = (mode->crtc_hsync_end - overlap) * n;
2266 mode->crtc_htotal = (mode->crtc_htotal - overlap) * n;
2267 mode->crtc_clock *= n;
2268 }
2269
intel_crtc_readout_derived_state(struct intel_crtc_state * crtc_state)2270 static void intel_crtc_readout_derived_state(struct intel_crtc_state *crtc_state)
2271 {
2272 struct drm_display_mode *mode = &crtc_state->hw.mode;
2273 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
2274 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2275
2276 /*
2277 * Start with the adjusted_mode crtc timings, which
2278 * have been filled with the transcoder timings.
2279 */
2280 drm_mode_copy(pipe_mode, adjusted_mode);
2281
2282 /* Expand MSO per-segment transcoder timings to full */
2283 intel_splitter_adjust_timings(crtc_state, pipe_mode);
2284
2285 /*
2286 * We want the full numbers in adjusted_mode normal timings,
2287 * adjusted_mode crtc timings are left with the raw transcoder
2288 * timings.
2289 */
2290 intel_mode_from_crtc_timings(adjusted_mode, pipe_mode);
2291
2292 /* Populate the "user" mode with full numbers */
2293 drm_mode_copy(mode, pipe_mode);
2294 intel_mode_from_crtc_timings(mode, mode);
2295 mode->hdisplay = drm_rect_width(&crtc_state->pipe_src) *
2296 intel_crtc_num_joined_pipes(crtc_state);
2297 mode->vdisplay = drm_rect_height(&crtc_state->pipe_src);
2298
2299 /* Derive per-pipe timings in case joiner is used */
2300 intel_joiner_adjust_timings(crtc_state, pipe_mode);
2301 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
2302
2303 intel_crtc_compute_pixel_rate(crtc_state);
2304 }
2305
intel_encoder_get_config(struct intel_encoder * encoder,struct intel_crtc_state * crtc_state)2306 void intel_encoder_get_config(struct intel_encoder *encoder,
2307 struct intel_crtc_state *crtc_state)
2308 {
2309 encoder->get_config(encoder, crtc_state);
2310
2311 intel_crtc_readout_derived_state(crtc_state);
2312 }
2313
intel_joiner_compute_pipe_src(struct intel_crtc_state * crtc_state)2314 static void intel_joiner_compute_pipe_src(struct intel_crtc_state *crtc_state)
2315 {
2316 int num_pipes = intel_crtc_num_joined_pipes(crtc_state);
2317 int width, height;
2318
2319 if (num_pipes == 1)
2320 return;
2321
2322 width = drm_rect_width(&crtc_state->pipe_src);
2323 height = drm_rect_height(&crtc_state->pipe_src);
2324
2325 drm_rect_init(&crtc_state->pipe_src, 0, 0,
2326 width / num_pipes, height);
2327 }
2328
intel_crtc_compute_pipe_src(struct intel_crtc_state * crtc_state)2329 static int intel_crtc_compute_pipe_src(struct intel_crtc_state *crtc_state)
2330 {
2331 struct intel_display *display = to_intel_display(crtc_state);
2332 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2333
2334 intel_joiner_compute_pipe_src(crtc_state);
2335
2336 /*
2337 * Pipe horizontal size must be even in:
2338 * - DVO ganged mode
2339 * - LVDS dual channel mode
2340 * - Double wide pipe
2341 */
2342 if (drm_rect_width(&crtc_state->pipe_src) & 1) {
2343 if (crtc_state->double_wide) {
2344 drm_dbg_kms(display->drm,
2345 "[CRTC:%d:%s] Odd pipe source width not supported with double wide pipe\n",
2346 crtc->base.base.id, crtc->base.name);
2347 return -EINVAL;
2348 }
2349
2350 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
2351 intel_is_dual_link_lvds(display)) {
2352 drm_dbg_kms(display->drm,
2353 "[CRTC:%d:%s] Odd pipe source width not supported with dual link LVDS\n",
2354 crtc->base.base.id, crtc->base.name);
2355 return -EINVAL;
2356 }
2357 }
2358
2359 return 0;
2360 }
2361
intel_crtc_compute_pipe_mode(struct intel_crtc_state * crtc_state)2362 static int intel_crtc_compute_pipe_mode(struct intel_crtc_state *crtc_state)
2363 {
2364 struct intel_display *display = to_intel_display(crtc_state);
2365 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2366 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2367 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
2368 int clock_limit = display->cdclk.max_dotclk_freq;
2369
2370 /*
2371 * Start with the adjusted_mode crtc timings, which
2372 * have been filled with the transcoder timings.
2373 */
2374 drm_mode_copy(pipe_mode, adjusted_mode);
2375
2376 /* Expand MSO per-segment transcoder timings to full */
2377 intel_splitter_adjust_timings(crtc_state, pipe_mode);
2378
2379 /* Derive per-pipe timings in case joiner is used */
2380 intel_joiner_adjust_timings(crtc_state, pipe_mode);
2381 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
2382
2383 if (DISPLAY_VER(display) < 4) {
2384 clock_limit = display->cdclk.max_cdclk_freq * 9 / 10;
2385
2386 /*
2387 * Enable double wide mode when the dot clock
2388 * is > 90% of the (display) core speed.
2389 */
2390 if (intel_crtc_supports_double_wide(crtc) &&
2391 pipe_mode->crtc_clock > clock_limit) {
2392 clock_limit = display->cdclk.max_dotclk_freq;
2393 crtc_state->double_wide = true;
2394 }
2395 }
2396
2397 if (pipe_mode->crtc_clock > clock_limit) {
2398 drm_dbg_kms(display->drm,
2399 "[CRTC:%d:%s] requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
2400 crtc->base.base.id, crtc->base.name,
2401 pipe_mode->crtc_clock, clock_limit,
2402 str_yes_no(crtc_state->double_wide));
2403 return -EINVAL;
2404 }
2405
2406 return 0;
2407 }
2408
intel_crtc_vblank_delay(const struct intel_crtc_state * crtc_state)2409 static int intel_crtc_vblank_delay(const struct intel_crtc_state *crtc_state)
2410 {
2411 struct intel_display *display = to_intel_display(crtc_state);
2412 int vblank_delay = 0;
2413
2414 if (!HAS_DSB(display))
2415 return 0;
2416
2417 vblank_delay = max(vblank_delay, intel_psr_min_vblank_delay(crtc_state));
2418
2419 return vblank_delay;
2420 }
2421
intel_crtc_compute_vblank_delay(struct intel_atomic_state * state,struct intel_crtc * crtc)2422 static int intel_crtc_compute_vblank_delay(struct intel_atomic_state *state,
2423 struct intel_crtc *crtc)
2424 {
2425 struct intel_display *display = to_intel_display(state);
2426 struct intel_crtc_state *crtc_state =
2427 intel_atomic_get_new_crtc_state(state, crtc);
2428 struct drm_display_mode *adjusted_mode =
2429 &crtc_state->hw.adjusted_mode;
2430 int vblank_delay, max_vblank_delay;
2431
2432 vblank_delay = intel_crtc_vblank_delay(crtc_state);
2433 max_vblank_delay = adjusted_mode->crtc_vblank_end - adjusted_mode->crtc_vblank_start - 1;
2434
2435 if (vblank_delay > max_vblank_delay) {
2436 drm_dbg_kms(display->drm, "[CRTC:%d:%s] vblank delay (%d) exceeds max (%d)\n",
2437 crtc->base.base.id, crtc->base.name, vblank_delay, max_vblank_delay);
2438 return -EINVAL;
2439 }
2440
2441 adjusted_mode->crtc_vblank_start += vblank_delay;
2442
2443 return 0;
2444 }
2445
intel_crtc_compute_config(struct intel_atomic_state * state,struct intel_crtc * crtc)2446 static int intel_crtc_compute_config(struct intel_atomic_state *state,
2447 struct intel_crtc *crtc)
2448 {
2449 struct intel_crtc_state *crtc_state =
2450 intel_atomic_get_new_crtc_state(state, crtc);
2451 int ret;
2452
2453 ret = intel_crtc_compute_vblank_delay(state, crtc);
2454 if (ret)
2455 return ret;
2456
2457 ret = intel_dpll_crtc_compute_clock(state, crtc);
2458 if (ret)
2459 return ret;
2460
2461 ret = intel_crtc_compute_pipe_src(crtc_state);
2462 if (ret)
2463 return ret;
2464
2465 ret = intel_crtc_compute_pipe_mode(crtc_state);
2466 if (ret)
2467 return ret;
2468
2469 intel_crtc_compute_pixel_rate(crtc_state);
2470
2471 if (crtc_state->has_pch_encoder)
2472 return ilk_fdi_compute_config(crtc, crtc_state);
2473
2474 return 0;
2475 }
2476
2477 static void
intel_reduce_m_n_ratio(u32 * num,u32 * den)2478 intel_reduce_m_n_ratio(u32 *num, u32 *den)
2479 {
2480 while (*num > DATA_LINK_M_N_MASK ||
2481 *den > DATA_LINK_M_N_MASK) {
2482 *num >>= 1;
2483 *den >>= 1;
2484 }
2485 }
2486
compute_m_n(u32 * ret_m,u32 * ret_n,u32 m,u32 n,u32 constant_n)2487 static void compute_m_n(u32 *ret_m, u32 *ret_n,
2488 u32 m, u32 n, u32 constant_n)
2489 {
2490 if (constant_n)
2491 *ret_n = constant_n;
2492 else
2493 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
2494
2495 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
2496 intel_reduce_m_n_ratio(ret_m, ret_n);
2497 }
2498
2499 void
intel_link_compute_m_n(u16 bits_per_pixel_x16,int nlanes,int pixel_clock,int link_clock,int bw_overhead,struct intel_link_m_n * m_n)2500 intel_link_compute_m_n(u16 bits_per_pixel_x16, int nlanes,
2501 int pixel_clock, int link_clock,
2502 int bw_overhead,
2503 struct intel_link_m_n *m_n)
2504 {
2505 u32 link_symbol_clock = intel_dp_link_symbol_clock(link_clock);
2506 u32 data_m = intel_dp_effective_data_rate(pixel_clock, bits_per_pixel_x16,
2507 bw_overhead);
2508 u32 data_n = drm_dp_max_dprx_data_rate(link_clock, nlanes);
2509
2510 /*
2511 * Windows/BIOS uses fixed M/N values always. Follow suit.
2512 *
2513 * Also several DP dongles in particular seem to be fussy
2514 * about too large link M/N values. Presumably the 20bit
2515 * value used by Windows/BIOS is acceptable to everyone.
2516 */
2517 m_n->tu = 64;
2518 compute_m_n(&m_n->data_m, &m_n->data_n,
2519 data_m, data_n,
2520 0x8000000);
2521
2522 compute_m_n(&m_n->link_m, &m_n->link_n,
2523 pixel_clock, link_symbol_clock,
2524 0x80000);
2525 }
2526
intel_panel_sanitize_ssc(struct intel_display * display)2527 void intel_panel_sanitize_ssc(struct intel_display *display)
2528 {
2529 /*
2530 * There may be no VBT; and if the BIOS enabled SSC we can
2531 * just keep using it to avoid unnecessary flicker. Whereas if the
2532 * BIOS isn't using it, don't assume it will work even if the VBT
2533 * indicates as much.
2534 */
2535 if (HAS_PCH_IBX(display) || HAS_PCH_CPT(display)) {
2536 bool bios_lvds_use_ssc = intel_de_read(display,
2537 PCH_DREF_CONTROL) &
2538 DREF_SSC1_ENABLE;
2539
2540 if (display->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
2541 drm_dbg_kms(display->drm,
2542 "SSC %s by BIOS, overriding VBT which says %s\n",
2543 str_enabled_disabled(bios_lvds_use_ssc),
2544 str_enabled_disabled(display->vbt.lvds_use_ssc));
2545 display->vbt.lvds_use_ssc = bios_lvds_use_ssc;
2546 }
2547 }
2548 }
2549
intel_zero_m_n(struct intel_link_m_n * m_n)2550 void intel_zero_m_n(struct intel_link_m_n *m_n)
2551 {
2552 /* corresponds to 0 register value */
2553 memset(m_n, 0, sizeof(*m_n));
2554 m_n->tu = 1;
2555 }
2556
intel_set_m_n(struct intel_display * display,const struct intel_link_m_n * m_n,i915_reg_t data_m_reg,i915_reg_t data_n_reg,i915_reg_t link_m_reg,i915_reg_t link_n_reg)2557 void intel_set_m_n(struct intel_display *display,
2558 const struct intel_link_m_n *m_n,
2559 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
2560 i915_reg_t link_m_reg, i915_reg_t link_n_reg)
2561 {
2562 intel_de_write(display, data_m_reg, TU_SIZE(m_n->tu) | m_n->data_m);
2563 intel_de_write(display, data_n_reg, m_n->data_n);
2564 intel_de_write(display, link_m_reg, m_n->link_m);
2565 /*
2566 * On BDW+ writing LINK_N arms the double buffered update
2567 * of all the M/N registers, so it must be written last.
2568 */
2569 intel_de_write(display, link_n_reg, m_n->link_n);
2570 }
2571
intel_cpu_transcoder_has_m2_n2(struct intel_display * display,enum transcoder transcoder)2572 bool intel_cpu_transcoder_has_m2_n2(struct intel_display *display,
2573 enum transcoder transcoder)
2574 {
2575 if (display->platform.haswell)
2576 return transcoder == TRANSCODER_EDP;
2577
2578 return IS_DISPLAY_VER(display, 5, 7) || display->platform.cherryview;
2579 }
2580
intel_cpu_transcoder_set_m1_n1(struct intel_crtc * crtc,enum transcoder transcoder,const struct intel_link_m_n * m_n)2581 void intel_cpu_transcoder_set_m1_n1(struct intel_crtc *crtc,
2582 enum transcoder transcoder,
2583 const struct intel_link_m_n *m_n)
2584 {
2585 struct intel_display *display = to_intel_display(crtc);
2586 enum pipe pipe = crtc->pipe;
2587
2588 if (DISPLAY_VER(display) >= 5)
2589 intel_set_m_n(display, m_n,
2590 PIPE_DATA_M1(display, transcoder),
2591 PIPE_DATA_N1(display, transcoder),
2592 PIPE_LINK_M1(display, transcoder),
2593 PIPE_LINK_N1(display, transcoder));
2594 else
2595 intel_set_m_n(display, m_n,
2596 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe),
2597 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe));
2598 }
2599
intel_cpu_transcoder_set_m2_n2(struct intel_crtc * crtc,enum transcoder transcoder,const struct intel_link_m_n * m_n)2600 void intel_cpu_transcoder_set_m2_n2(struct intel_crtc *crtc,
2601 enum transcoder transcoder,
2602 const struct intel_link_m_n *m_n)
2603 {
2604 struct intel_display *display = to_intel_display(crtc);
2605
2606 if (!intel_cpu_transcoder_has_m2_n2(display, transcoder))
2607 return;
2608
2609 intel_set_m_n(display, m_n,
2610 PIPE_DATA_M2(display, transcoder),
2611 PIPE_DATA_N2(display, transcoder),
2612 PIPE_LINK_M2(display, transcoder),
2613 PIPE_LINK_N2(display, transcoder));
2614 }
2615
2616 static bool
transcoder_has_vrr(const struct intel_crtc_state * crtc_state)2617 transcoder_has_vrr(const struct intel_crtc_state *crtc_state)
2618 {
2619 struct intel_display *display = to_intel_display(crtc_state);
2620 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2621
2622 return HAS_VRR(display) && !transcoder_is_dsi(cpu_transcoder);
2623 }
2624
intel_set_transcoder_timings(const struct intel_crtc_state * crtc_state)2625 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state)
2626 {
2627 struct intel_display *display = to_intel_display(crtc_state);
2628 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2629 enum pipe pipe = crtc->pipe;
2630 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2631 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2632 u32 crtc_vdisplay, crtc_vtotal, crtc_vblank_start, crtc_vblank_end;
2633 int vsyncshift = 0;
2634
2635 drm_WARN_ON(display->drm, transcoder_is_dsi(cpu_transcoder));
2636
2637 /* We need to be careful not to changed the adjusted mode, for otherwise
2638 * the hw state checker will get angry at the mismatch. */
2639 crtc_vdisplay = adjusted_mode->crtc_vdisplay;
2640 crtc_vtotal = adjusted_mode->crtc_vtotal;
2641 crtc_vblank_start = adjusted_mode->crtc_vblank_start;
2642 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
2643
2644 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
2645 /* the chip adds 2 halflines automatically */
2646 crtc_vtotal -= 1;
2647 crtc_vblank_end -= 1;
2648
2649 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
2650 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
2651 else
2652 vsyncshift = adjusted_mode->crtc_hsync_start -
2653 adjusted_mode->crtc_htotal / 2;
2654 if (vsyncshift < 0)
2655 vsyncshift += adjusted_mode->crtc_htotal;
2656 }
2657
2658 /*
2659 * VBLANK_START no longer works on ADL+, instead we must use
2660 * TRANS_SET_CONTEXT_LATENCY to configure the pipe vblank start.
2661 */
2662 if (DISPLAY_VER(display) >= 13) {
2663 intel_de_write(display,
2664 TRANS_SET_CONTEXT_LATENCY(display, cpu_transcoder),
2665 crtc_vblank_start - crtc_vdisplay);
2666
2667 /*
2668 * VBLANK_START not used by hw, just clear it
2669 * to make it stand out in register dumps.
2670 */
2671 crtc_vblank_start = 1;
2672 }
2673
2674 if (DISPLAY_VER(display) >= 4)
2675 intel_de_write(display,
2676 TRANS_VSYNCSHIFT(display, cpu_transcoder),
2677 vsyncshift);
2678
2679 intel_de_write(display, TRANS_HTOTAL(display, cpu_transcoder),
2680 HACTIVE(adjusted_mode->crtc_hdisplay - 1) |
2681 HTOTAL(adjusted_mode->crtc_htotal - 1));
2682 intel_de_write(display, TRANS_HBLANK(display, cpu_transcoder),
2683 HBLANK_START(adjusted_mode->crtc_hblank_start - 1) |
2684 HBLANK_END(adjusted_mode->crtc_hblank_end - 1));
2685 intel_de_write(display, TRANS_HSYNC(display, cpu_transcoder),
2686 HSYNC_START(adjusted_mode->crtc_hsync_start - 1) |
2687 HSYNC_END(adjusted_mode->crtc_hsync_end - 1));
2688
2689 /*
2690 * For platforms that always use VRR Timing Generator, the VTOTAL.Vtotal
2691 * bits are not required. Since the support for these bits is going to
2692 * be deprecated in upcoming platforms, avoid writing these bits for the
2693 * platforms that do not use legacy Timing Generator.
2694 */
2695 if (intel_vrr_always_use_vrr_tg(display))
2696 crtc_vtotal = 1;
2697
2698 intel_de_write(display, TRANS_VTOTAL(display, cpu_transcoder),
2699 VACTIVE(crtc_vdisplay - 1) |
2700 VTOTAL(crtc_vtotal - 1));
2701 intel_de_write(display, TRANS_VBLANK(display, cpu_transcoder),
2702 VBLANK_START(crtc_vblank_start - 1) |
2703 VBLANK_END(crtc_vblank_end - 1));
2704 intel_de_write(display, TRANS_VSYNC(display, cpu_transcoder),
2705 VSYNC_START(adjusted_mode->crtc_vsync_start - 1) |
2706 VSYNC_END(adjusted_mode->crtc_vsync_end - 1));
2707
2708 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
2709 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
2710 * documented on the DDI_FUNC_CTL register description, EDP Input Select
2711 * bits. */
2712 if (display->platform.haswell && cpu_transcoder == TRANSCODER_EDP &&
2713 (pipe == PIPE_B || pipe == PIPE_C))
2714 intel_de_write(display, TRANS_VTOTAL(display, pipe),
2715 VACTIVE(crtc_vdisplay - 1) |
2716 VTOTAL(crtc_vtotal - 1));
2717
2718 if (DISPLAY_VER(display) >= 30) {
2719 /*
2720 * Address issues for resolutions with high refresh rate that
2721 * have small Hblank, specifically where Hblank is smaller than
2722 * one MTP. Simulations indicate this will address the
2723 * jitter issues that currently causes BS to be immediately
2724 * followed by BE which DPRX devices are unable to handle.
2725 * https://groups.vesa.org/wg/DP/document/20494
2726 */
2727 intel_de_write(display, DP_MIN_HBLANK_CTL(cpu_transcoder),
2728 crtc_state->min_hblank);
2729 }
2730 }
2731
intel_set_transcoder_timings_lrr(const struct intel_crtc_state * crtc_state)2732 static void intel_set_transcoder_timings_lrr(const struct intel_crtc_state *crtc_state)
2733 {
2734 struct intel_display *display = to_intel_display(crtc_state);
2735 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2736 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2737 u32 crtc_vdisplay, crtc_vtotal, crtc_vblank_start, crtc_vblank_end;
2738
2739 drm_WARN_ON(display->drm, transcoder_is_dsi(cpu_transcoder));
2740
2741 crtc_vdisplay = adjusted_mode->crtc_vdisplay;
2742 crtc_vtotal = adjusted_mode->crtc_vtotal;
2743 crtc_vblank_start = adjusted_mode->crtc_vblank_start;
2744 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
2745
2746 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
2747 /* the chip adds 2 halflines automatically */
2748 crtc_vtotal -= 1;
2749 crtc_vblank_end -= 1;
2750 }
2751
2752 if (DISPLAY_VER(display) >= 13) {
2753 intel_de_write(display,
2754 TRANS_SET_CONTEXT_LATENCY(display, cpu_transcoder),
2755 crtc_vblank_start - crtc_vdisplay);
2756
2757 /*
2758 * VBLANK_START not used by hw, just clear it
2759 * to make it stand out in register dumps.
2760 */
2761 crtc_vblank_start = 1;
2762 }
2763
2764 /*
2765 * The hardware actually ignores TRANS_VBLANK.VBLANK_END in DP mode.
2766 * But let's write it anyway to keep the state checker happy.
2767 */
2768 intel_de_write(display, TRANS_VBLANK(display, cpu_transcoder),
2769 VBLANK_START(crtc_vblank_start - 1) |
2770 VBLANK_END(crtc_vblank_end - 1));
2771 /*
2772 * For platforms that always use VRR Timing Generator, the VTOTAL.Vtotal
2773 * bits are not required. Since the support for these bits is going to
2774 * be deprecated in upcoming platforms, avoid writing these bits for the
2775 * platforms that do not use legacy Timing Generator.
2776 */
2777 if (intel_vrr_always_use_vrr_tg(display))
2778 crtc_vtotal = 1;
2779
2780 /*
2781 * The double buffer latch point for TRANS_VTOTAL
2782 * is the transcoder's undelayed vblank.
2783 */
2784 intel_de_write(display, TRANS_VTOTAL(display, cpu_transcoder),
2785 VACTIVE(crtc_vdisplay - 1) |
2786 VTOTAL(crtc_vtotal - 1));
2787
2788 intel_vrr_set_fixed_rr_timings(crtc_state);
2789 intel_vrr_transcoder_enable(crtc_state);
2790 }
2791
intel_set_pipe_src_size(const struct intel_crtc_state * crtc_state)2792 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
2793 {
2794 struct intel_display *display = to_intel_display(crtc_state);
2795 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2796 int width = drm_rect_width(&crtc_state->pipe_src);
2797 int height = drm_rect_height(&crtc_state->pipe_src);
2798 enum pipe pipe = crtc->pipe;
2799
2800 /* pipesrc controls the size that is scaled from, which should
2801 * always be the user's requested size.
2802 */
2803 intel_de_write(display, PIPESRC(display, pipe),
2804 PIPESRC_WIDTH(width - 1) | PIPESRC_HEIGHT(height - 1));
2805 }
2806
intel_pipe_is_interlaced(const struct intel_crtc_state * crtc_state)2807 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state)
2808 {
2809 struct intel_display *display = to_intel_display(crtc_state);
2810 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2811
2812 if (DISPLAY_VER(display) == 2)
2813 return false;
2814
2815 if (DISPLAY_VER(display) >= 9 ||
2816 display->platform.broadwell || display->platform.haswell)
2817 return intel_de_read(display,
2818 TRANSCONF(display, cpu_transcoder)) & TRANSCONF_INTERLACE_MASK_HSW;
2819 else
2820 return intel_de_read(display,
2821 TRANSCONF(display, cpu_transcoder)) & TRANSCONF_INTERLACE_MASK;
2822 }
2823
intel_get_transcoder_timings(struct intel_crtc * crtc,struct intel_crtc_state * pipe_config)2824 static void intel_get_transcoder_timings(struct intel_crtc *crtc,
2825 struct intel_crtc_state *pipe_config)
2826 {
2827 struct intel_display *display = to_intel_display(crtc);
2828 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
2829 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
2830 u32 tmp;
2831
2832 tmp = intel_de_read(display, TRANS_HTOTAL(display, cpu_transcoder));
2833 adjusted_mode->crtc_hdisplay = REG_FIELD_GET(HACTIVE_MASK, tmp) + 1;
2834 adjusted_mode->crtc_htotal = REG_FIELD_GET(HTOTAL_MASK, tmp) + 1;
2835
2836 if (!transcoder_is_dsi(cpu_transcoder)) {
2837 tmp = intel_de_read(display,
2838 TRANS_HBLANK(display, cpu_transcoder));
2839 adjusted_mode->crtc_hblank_start = REG_FIELD_GET(HBLANK_START_MASK, tmp) + 1;
2840 adjusted_mode->crtc_hblank_end = REG_FIELD_GET(HBLANK_END_MASK, tmp) + 1;
2841 }
2842
2843 tmp = intel_de_read(display, TRANS_HSYNC(display, cpu_transcoder));
2844 adjusted_mode->crtc_hsync_start = REG_FIELD_GET(HSYNC_START_MASK, tmp) + 1;
2845 adjusted_mode->crtc_hsync_end = REG_FIELD_GET(HSYNC_END_MASK, tmp) + 1;
2846
2847 tmp = intel_de_read(display, TRANS_VTOTAL(display, cpu_transcoder));
2848 adjusted_mode->crtc_vdisplay = REG_FIELD_GET(VACTIVE_MASK, tmp) + 1;
2849 adjusted_mode->crtc_vtotal = REG_FIELD_GET(VTOTAL_MASK, tmp) + 1;
2850
2851 /* FIXME TGL+ DSI transcoders have this! */
2852 if (!transcoder_is_dsi(cpu_transcoder)) {
2853 tmp = intel_de_read(display,
2854 TRANS_VBLANK(display, cpu_transcoder));
2855 adjusted_mode->crtc_vblank_start = REG_FIELD_GET(VBLANK_START_MASK, tmp) + 1;
2856 adjusted_mode->crtc_vblank_end = REG_FIELD_GET(VBLANK_END_MASK, tmp) + 1;
2857 }
2858 tmp = intel_de_read(display, TRANS_VSYNC(display, cpu_transcoder));
2859 adjusted_mode->crtc_vsync_start = REG_FIELD_GET(VSYNC_START_MASK, tmp) + 1;
2860 adjusted_mode->crtc_vsync_end = REG_FIELD_GET(VSYNC_END_MASK, tmp) + 1;
2861
2862 if (intel_pipe_is_interlaced(pipe_config)) {
2863 adjusted_mode->flags |= DRM_MODE_FLAG_INTERLACE;
2864 adjusted_mode->crtc_vtotal += 1;
2865 adjusted_mode->crtc_vblank_end += 1;
2866 }
2867
2868 if (DISPLAY_VER(display) >= 13 && !transcoder_is_dsi(cpu_transcoder))
2869 adjusted_mode->crtc_vblank_start =
2870 adjusted_mode->crtc_vdisplay +
2871 intel_de_read(display,
2872 TRANS_SET_CONTEXT_LATENCY(display, cpu_transcoder));
2873
2874 if (DISPLAY_VER(display) >= 30)
2875 pipe_config->min_hblank = intel_de_read(display,
2876 DP_MIN_HBLANK_CTL(cpu_transcoder));
2877 }
2878
intel_joiner_adjust_pipe_src(struct intel_crtc_state * crtc_state)2879 static void intel_joiner_adjust_pipe_src(struct intel_crtc_state *crtc_state)
2880 {
2881 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2882 int num_pipes = intel_crtc_num_joined_pipes(crtc_state);
2883 enum pipe primary_pipe, pipe = crtc->pipe;
2884 int width;
2885
2886 if (num_pipes == 1)
2887 return;
2888
2889 primary_pipe = joiner_primary_pipe(crtc_state);
2890 width = drm_rect_width(&crtc_state->pipe_src);
2891
2892 drm_rect_translate_to(&crtc_state->pipe_src,
2893 (pipe - primary_pipe) * width, 0);
2894 }
2895
intel_get_pipe_src_size(struct intel_crtc * crtc,struct intel_crtc_state * pipe_config)2896 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
2897 struct intel_crtc_state *pipe_config)
2898 {
2899 struct intel_display *display = to_intel_display(crtc);
2900 u32 tmp;
2901
2902 tmp = intel_de_read(display, PIPESRC(display, crtc->pipe));
2903
2904 drm_rect_init(&pipe_config->pipe_src, 0, 0,
2905 REG_FIELD_GET(PIPESRC_WIDTH_MASK, tmp) + 1,
2906 REG_FIELD_GET(PIPESRC_HEIGHT_MASK, tmp) + 1);
2907
2908 intel_joiner_adjust_pipe_src(pipe_config);
2909 }
2910
i9xx_set_pipeconf(const struct intel_crtc_state * crtc_state)2911 void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
2912 {
2913 struct intel_display *display = to_intel_display(crtc_state);
2914 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2915 u32 val = 0;
2916
2917 /*
2918 * - We keep both pipes enabled on 830
2919 * - During modeset the pipe is still disabled and must remain so
2920 * - During fastset the pipe is already enabled and must remain so
2921 */
2922 if (display->platform.i830 || !intel_crtc_needs_modeset(crtc_state))
2923 val |= TRANSCONF_ENABLE;
2924
2925 if (crtc_state->double_wide)
2926 val |= TRANSCONF_DOUBLE_WIDE;
2927
2928 /* only g4x and later have fancy bpc/dither controls */
2929 if (display->platform.g4x || display->platform.valleyview ||
2930 display->platform.cherryview) {
2931 /* Bspec claims that we can't use dithering for 30bpp pipes. */
2932 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
2933 val |= TRANSCONF_DITHER_EN |
2934 TRANSCONF_DITHER_TYPE_SP;
2935
2936 switch (crtc_state->pipe_bpp) {
2937 default:
2938 /* Case prevented by intel_choose_pipe_bpp_dither. */
2939 MISSING_CASE(crtc_state->pipe_bpp);
2940 fallthrough;
2941 case 18:
2942 val |= TRANSCONF_BPC_6;
2943 break;
2944 case 24:
2945 val |= TRANSCONF_BPC_8;
2946 break;
2947 case 30:
2948 val |= TRANSCONF_BPC_10;
2949 break;
2950 }
2951 }
2952
2953 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
2954 if (DISPLAY_VER(display) < 4 ||
2955 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
2956 val |= TRANSCONF_INTERLACE_W_FIELD_INDICATION;
2957 else
2958 val |= TRANSCONF_INTERLACE_W_SYNC_SHIFT;
2959 } else {
2960 val |= TRANSCONF_INTERLACE_PROGRESSIVE;
2961 }
2962
2963 if ((display->platform.valleyview || display->platform.cherryview) &&
2964 crtc_state->limited_color_range)
2965 val |= TRANSCONF_COLOR_RANGE_SELECT;
2966
2967 val |= TRANSCONF_GAMMA_MODE(crtc_state->gamma_mode);
2968
2969 if (crtc_state->wgc_enable)
2970 val |= TRANSCONF_WGC_ENABLE;
2971
2972 val |= TRANSCONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1);
2973
2974 intel_de_write(display, TRANSCONF(display, cpu_transcoder), val);
2975 intel_de_posting_read(display, TRANSCONF(display, cpu_transcoder));
2976 }
2977
2978 static enum intel_output_format
bdw_get_pipe_misc_output_format(struct intel_crtc * crtc)2979 bdw_get_pipe_misc_output_format(struct intel_crtc *crtc)
2980 {
2981 struct intel_display *display = to_intel_display(crtc);
2982 u32 tmp;
2983
2984 tmp = intel_de_read(display, PIPE_MISC(crtc->pipe));
2985
2986 if (tmp & PIPE_MISC_YUV420_ENABLE) {
2987 /*
2988 * We support 4:2:0 in full blend mode only.
2989 * For xe3_lpd+ this is implied in YUV420 Enable bit.
2990 * Ensure the same for prior platforms in YUV420 Mode bit.
2991 */
2992 if (DISPLAY_VER(display) < 30)
2993 drm_WARN_ON(display->drm,
2994 (tmp & PIPE_MISC_YUV420_MODE_FULL_BLEND) == 0);
2995
2996 return INTEL_OUTPUT_FORMAT_YCBCR420;
2997 } else if (tmp & PIPE_MISC_OUTPUT_COLORSPACE_YUV) {
2998 return INTEL_OUTPUT_FORMAT_YCBCR444;
2999 } else {
3000 return INTEL_OUTPUT_FORMAT_RGB;
3001 }
3002 }
3003
i9xx_get_pipe_config(struct intel_crtc * crtc,struct intel_crtc_state * pipe_config)3004 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
3005 struct intel_crtc_state *pipe_config)
3006 {
3007 struct intel_display *display = to_intel_display(crtc);
3008 enum intel_display_power_domain power_domain;
3009 enum transcoder cpu_transcoder = (enum transcoder)crtc->pipe;
3010 intel_wakeref_t wakeref;
3011 bool ret = false;
3012 u32 tmp;
3013
3014 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
3015 wakeref = intel_display_power_get_if_enabled(display, power_domain);
3016 if (!wakeref)
3017 return false;
3018
3019 tmp = intel_de_read(display, TRANSCONF(display, cpu_transcoder));
3020 if (!(tmp & TRANSCONF_ENABLE))
3021 goto out;
3022
3023 pipe_config->cpu_transcoder = cpu_transcoder;
3024
3025 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
3026 pipe_config->sink_format = pipe_config->output_format;
3027
3028 if (display->platform.g4x || display->platform.valleyview ||
3029 display->platform.cherryview) {
3030 switch (tmp & TRANSCONF_BPC_MASK) {
3031 case TRANSCONF_BPC_6:
3032 pipe_config->pipe_bpp = 18;
3033 break;
3034 case TRANSCONF_BPC_8:
3035 pipe_config->pipe_bpp = 24;
3036 break;
3037 case TRANSCONF_BPC_10:
3038 pipe_config->pipe_bpp = 30;
3039 break;
3040 default:
3041 MISSING_CASE(tmp);
3042 break;
3043 }
3044 }
3045
3046 if ((display->platform.valleyview || display->platform.cherryview) &&
3047 (tmp & TRANSCONF_COLOR_RANGE_SELECT))
3048 pipe_config->limited_color_range = true;
3049
3050 pipe_config->gamma_mode = REG_FIELD_GET(TRANSCONF_GAMMA_MODE_MASK_I9XX, tmp);
3051
3052 pipe_config->framestart_delay = REG_FIELD_GET(TRANSCONF_FRAME_START_DELAY_MASK, tmp) + 1;
3053
3054 if ((display->platform.valleyview || display->platform.cherryview) &&
3055 (tmp & TRANSCONF_WGC_ENABLE))
3056 pipe_config->wgc_enable = true;
3057
3058 intel_color_get_config(pipe_config);
3059
3060 if (HAS_DOUBLE_WIDE(display))
3061 pipe_config->double_wide = tmp & TRANSCONF_DOUBLE_WIDE;
3062
3063 intel_get_transcoder_timings(crtc, pipe_config);
3064 intel_get_pipe_src_size(crtc, pipe_config);
3065
3066 i9xx_pfit_get_config(pipe_config);
3067
3068 i9xx_dpll_get_hw_state(crtc, &pipe_config->dpll_hw_state);
3069
3070 if (DISPLAY_VER(display) >= 4) {
3071 tmp = pipe_config->dpll_hw_state.i9xx.dpll_md;
3072 pipe_config->pixel_multiplier =
3073 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
3074 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
3075 } else if (display->platform.i945g || display->platform.i945gm ||
3076 display->platform.g33 || display->platform.pineview) {
3077 tmp = pipe_config->dpll_hw_state.i9xx.dpll;
3078 pipe_config->pixel_multiplier =
3079 ((tmp & SDVO_MULTIPLIER_MASK)
3080 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
3081 } else {
3082 /* Note that on i915G/GM the pixel multiplier is in the sdvo
3083 * port and will be fixed up in the encoder->get_config
3084 * function. */
3085 pipe_config->pixel_multiplier = 1;
3086 }
3087
3088 if (display->platform.cherryview)
3089 chv_crtc_clock_get(pipe_config);
3090 else if (display->platform.valleyview)
3091 vlv_crtc_clock_get(pipe_config);
3092 else
3093 i9xx_crtc_clock_get(pipe_config);
3094
3095 /*
3096 * Normally the dotclock is filled in by the encoder .get_config()
3097 * but in case the pipe is enabled w/o any ports we need a sane
3098 * default.
3099 */
3100 pipe_config->hw.adjusted_mode.crtc_clock =
3101 pipe_config->port_clock / pipe_config->pixel_multiplier;
3102
3103 ret = true;
3104
3105 out:
3106 intel_display_power_put(display, power_domain, wakeref);
3107
3108 return ret;
3109 }
3110
ilk_set_pipeconf(const struct intel_crtc_state * crtc_state)3111 void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state)
3112 {
3113 struct intel_display *display = to_intel_display(crtc_state);
3114 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
3115 u32 val = 0;
3116
3117 /*
3118 * - During modeset the pipe is still disabled and must remain so
3119 * - During fastset the pipe is already enabled and must remain so
3120 */
3121 if (!intel_crtc_needs_modeset(crtc_state))
3122 val |= TRANSCONF_ENABLE;
3123
3124 switch (crtc_state->pipe_bpp) {
3125 default:
3126 /* Case prevented by intel_choose_pipe_bpp_dither. */
3127 MISSING_CASE(crtc_state->pipe_bpp);
3128 fallthrough;
3129 case 18:
3130 val |= TRANSCONF_BPC_6;
3131 break;
3132 case 24:
3133 val |= TRANSCONF_BPC_8;
3134 break;
3135 case 30:
3136 val |= TRANSCONF_BPC_10;
3137 break;
3138 case 36:
3139 val |= TRANSCONF_BPC_12;
3140 break;
3141 }
3142
3143 if (crtc_state->dither)
3144 val |= TRANSCONF_DITHER_EN | TRANSCONF_DITHER_TYPE_SP;
3145
3146 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
3147 val |= TRANSCONF_INTERLACE_IF_ID_ILK;
3148 else
3149 val |= TRANSCONF_INTERLACE_PF_PD_ILK;
3150
3151 /*
3152 * This would end up with an odd purple hue over
3153 * the entire display. Make sure we don't do it.
3154 */
3155 drm_WARN_ON(display->drm, crtc_state->limited_color_range &&
3156 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
3157
3158 if (crtc_state->limited_color_range &&
3159 !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
3160 val |= TRANSCONF_COLOR_RANGE_SELECT;
3161
3162 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
3163 val |= TRANSCONF_OUTPUT_COLORSPACE_YUV709;
3164
3165 val |= TRANSCONF_GAMMA_MODE(crtc_state->gamma_mode);
3166
3167 val |= TRANSCONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1);
3168 val |= TRANSCONF_MSA_TIMING_DELAY(crtc_state->msa_timing_delay);
3169
3170 intel_de_write(display, TRANSCONF(display, cpu_transcoder), val);
3171 intel_de_posting_read(display, TRANSCONF(display, cpu_transcoder));
3172 }
3173
hsw_set_transconf(const struct intel_crtc_state * crtc_state)3174 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state)
3175 {
3176 struct intel_display *display = to_intel_display(crtc_state);
3177 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
3178 u32 val = 0;
3179
3180 /*
3181 * - During modeset the pipe is still disabled and must remain so
3182 * - During fastset the pipe is already enabled and must remain so
3183 */
3184 if (!intel_crtc_needs_modeset(crtc_state))
3185 val |= TRANSCONF_ENABLE;
3186
3187 if (display->platform.haswell && crtc_state->dither)
3188 val |= TRANSCONF_DITHER_EN | TRANSCONF_DITHER_TYPE_SP;
3189
3190 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
3191 val |= TRANSCONF_INTERLACE_IF_ID_ILK;
3192 else
3193 val |= TRANSCONF_INTERLACE_PF_PD_ILK;
3194
3195 if (display->platform.haswell &&
3196 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
3197 val |= TRANSCONF_OUTPUT_COLORSPACE_YUV_HSW;
3198
3199 intel_de_write(display, TRANSCONF(display, cpu_transcoder), val);
3200 intel_de_posting_read(display, TRANSCONF(display, cpu_transcoder));
3201 }
3202
bdw_set_pipe_misc(struct intel_dsb * dsb,const struct intel_crtc_state * crtc_state)3203 static void bdw_set_pipe_misc(struct intel_dsb *dsb,
3204 const struct intel_crtc_state *crtc_state)
3205 {
3206 struct intel_display *display = to_intel_display(crtc_state);
3207 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3208 u32 val = 0;
3209
3210 switch (crtc_state->pipe_bpp) {
3211 case 18:
3212 val |= PIPE_MISC_BPC_6;
3213 break;
3214 case 24:
3215 val |= PIPE_MISC_BPC_8;
3216 break;
3217 case 30:
3218 val |= PIPE_MISC_BPC_10;
3219 break;
3220 case 36:
3221 /* Port output 12BPC defined for ADLP+ */
3222 if (DISPLAY_VER(display) >= 13)
3223 val |= PIPE_MISC_BPC_12_ADLP;
3224 break;
3225 default:
3226 MISSING_CASE(crtc_state->pipe_bpp);
3227 break;
3228 }
3229
3230 if (crtc_state->dither)
3231 val |= PIPE_MISC_DITHER_ENABLE | PIPE_MISC_DITHER_TYPE_SP;
3232
3233 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
3234 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
3235 val |= PIPE_MISC_OUTPUT_COLORSPACE_YUV;
3236
3237 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
3238 val |= DISPLAY_VER(display) >= 30 ? PIPE_MISC_YUV420_ENABLE :
3239 PIPE_MISC_YUV420_ENABLE | PIPE_MISC_YUV420_MODE_FULL_BLEND;
3240
3241 if (DISPLAY_VER(display) >= 11 && is_hdr_mode(crtc_state))
3242 val |= PIPE_MISC_HDR_MODE_PRECISION;
3243
3244 if (DISPLAY_VER(display) >= 12)
3245 val |= PIPE_MISC_PIXEL_ROUNDING_TRUNC;
3246
3247 /* allow PSR with sprite enabled */
3248 if (display->platform.broadwell)
3249 val |= PIPE_MISC_PSR_MASK_SPRITE_ENABLE;
3250
3251 intel_de_write_dsb(display, dsb, PIPE_MISC(crtc->pipe), val);
3252 }
3253
bdw_get_pipe_misc_bpp(struct intel_crtc * crtc)3254 int bdw_get_pipe_misc_bpp(struct intel_crtc *crtc)
3255 {
3256 struct intel_display *display = to_intel_display(crtc);
3257 u32 tmp;
3258
3259 tmp = intel_de_read(display, PIPE_MISC(crtc->pipe));
3260
3261 switch (tmp & PIPE_MISC_BPC_MASK) {
3262 case PIPE_MISC_BPC_6:
3263 return 18;
3264 case PIPE_MISC_BPC_8:
3265 return 24;
3266 case PIPE_MISC_BPC_10:
3267 return 30;
3268 /*
3269 * PORT OUTPUT 12 BPC defined for ADLP+.
3270 *
3271 * TODO:
3272 * For previous platforms with DSI interface, bits 5:7
3273 * are used for storing pipe_bpp irrespective of dithering.
3274 * Since the value of 12 BPC is not defined for these bits
3275 * on older platforms, need to find a workaround for 12 BPC
3276 * MIPI DSI HW readout.
3277 */
3278 case PIPE_MISC_BPC_12_ADLP:
3279 if (DISPLAY_VER(display) >= 13)
3280 return 36;
3281 fallthrough;
3282 default:
3283 MISSING_CASE(tmp);
3284 return 0;
3285 }
3286 }
3287
ilk_get_lanes_required(int target_clock,int link_bw,int bpp)3288 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp)
3289 {
3290 /*
3291 * Account for spread spectrum to avoid
3292 * oversubscribing the link. Max center spread
3293 * is 2.5%; use 5% for safety's sake.
3294 */
3295 u32 bps = target_clock * bpp * 21 / 20;
3296 return DIV_ROUND_UP(bps, link_bw * 8);
3297 }
3298
intel_get_m_n(struct intel_display * display,struct intel_link_m_n * m_n,i915_reg_t data_m_reg,i915_reg_t data_n_reg,i915_reg_t link_m_reg,i915_reg_t link_n_reg)3299 void intel_get_m_n(struct intel_display *display,
3300 struct intel_link_m_n *m_n,
3301 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
3302 i915_reg_t link_m_reg, i915_reg_t link_n_reg)
3303 {
3304 m_n->link_m = intel_de_read(display, link_m_reg) & DATA_LINK_M_N_MASK;
3305 m_n->link_n = intel_de_read(display, link_n_reg) & DATA_LINK_M_N_MASK;
3306 m_n->data_m = intel_de_read(display, data_m_reg) & DATA_LINK_M_N_MASK;
3307 m_n->data_n = intel_de_read(display, data_n_reg) & DATA_LINK_M_N_MASK;
3308 m_n->tu = REG_FIELD_GET(TU_SIZE_MASK, intel_de_read(display, data_m_reg)) + 1;
3309 }
3310
intel_cpu_transcoder_get_m1_n1(struct intel_crtc * crtc,enum transcoder transcoder,struct intel_link_m_n * m_n)3311 void intel_cpu_transcoder_get_m1_n1(struct intel_crtc *crtc,
3312 enum transcoder transcoder,
3313 struct intel_link_m_n *m_n)
3314 {
3315 struct intel_display *display = to_intel_display(crtc);
3316 enum pipe pipe = crtc->pipe;
3317
3318 if (DISPLAY_VER(display) >= 5)
3319 intel_get_m_n(display, m_n,
3320 PIPE_DATA_M1(display, transcoder),
3321 PIPE_DATA_N1(display, transcoder),
3322 PIPE_LINK_M1(display, transcoder),
3323 PIPE_LINK_N1(display, transcoder));
3324 else
3325 intel_get_m_n(display, m_n,
3326 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe),
3327 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe));
3328 }
3329
intel_cpu_transcoder_get_m2_n2(struct intel_crtc * crtc,enum transcoder transcoder,struct intel_link_m_n * m_n)3330 void intel_cpu_transcoder_get_m2_n2(struct intel_crtc *crtc,
3331 enum transcoder transcoder,
3332 struct intel_link_m_n *m_n)
3333 {
3334 struct intel_display *display = to_intel_display(crtc);
3335
3336 if (!intel_cpu_transcoder_has_m2_n2(display, transcoder))
3337 return;
3338
3339 intel_get_m_n(display, m_n,
3340 PIPE_DATA_M2(display, transcoder),
3341 PIPE_DATA_N2(display, transcoder),
3342 PIPE_LINK_M2(display, transcoder),
3343 PIPE_LINK_N2(display, transcoder));
3344 }
3345
ilk_get_pipe_config(struct intel_crtc * crtc,struct intel_crtc_state * pipe_config)3346 static bool ilk_get_pipe_config(struct intel_crtc *crtc,
3347 struct intel_crtc_state *pipe_config)
3348 {
3349 struct intel_display *display = to_intel_display(crtc);
3350 enum intel_display_power_domain power_domain;
3351 enum transcoder cpu_transcoder = (enum transcoder)crtc->pipe;
3352 intel_wakeref_t wakeref;
3353 bool ret = false;
3354 u32 tmp;
3355
3356 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
3357 wakeref = intel_display_power_get_if_enabled(display, power_domain);
3358 if (!wakeref)
3359 return false;
3360
3361 tmp = intel_de_read(display, TRANSCONF(display, cpu_transcoder));
3362 if (!(tmp & TRANSCONF_ENABLE))
3363 goto out;
3364
3365 pipe_config->cpu_transcoder = cpu_transcoder;
3366
3367 switch (tmp & TRANSCONF_BPC_MASK) {
3368 case TRANSCONF_BPC_6:
3369 pipe_config->pipe_bpp = 18;
3370 break;
3371 case TRANSCONF_BPC_8:
3372 pipe_config->pipe_bpp = 24;
3373 break;
3374 case TRANSCONF_BPC_10:
3375 pipe_config->pipe_bpp = 30;
3376 break;
3377 case TRANSCONF_BPC_12:
3378 pipe_config->pipe_bpp = 36;
3379 break;
3380 default:
3381 break;
3382 }
3383
3384 if (tmp & TRANSCONF_COLOR_RANGE_SELECT)
3385 pipe_config->limited_color_range = true;
3386
3387 switch (tmp & TRANSCONF_OUTPUT_COLORSPACE_MASK) {
3388 case TRANSCONF_OUTPUT_COLORSPACE_YUV601:
3389 case TRANSCONF_OUTPUT_COLORSPACE_YUV709:
3390 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
3391 break;
3392 default:
3393 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
3394 break;
3395 }
3396
3397 pipe_config->sink_format = pipe_config->output_format;
3398
3399 pipe_config->gamma_mode = REG_FIELD_GET(TRANSCONF_GAMMA_MODE_MASK_ILK, tmp);
3400
3401 pipe_config->framestart_delay = REG_FIELD_GET(TRANSCONF_FRAME_START_DELAY_MASK, tmp) + 1;
3402
3403 pipe_config->msa_timing_delay = REG_FIELD_GET(TRANSCONF_MSA_TIMING_DELAY_MASK, tmp);
3404
3405 intel_color_get_config(pipe_config);
3406
3407 pipe_config->pixel_multiplier = 1;
3408
3409 ilk_pch_get_config(pipe_config);
3410
3411 intel_get_transcoder_timings(crtc, pipe_config);
3412 intel_get_pipe_src_size(crtc, pipe_config);
3413
3414 ilk_pfit_get_config(pipe_config);
3415
3416 ret = true;
3417
3418 out:
3419 intel_display_power_put(display, power_domain, wakeref);
3420
3421 return ret;
3422 }
3423
joiner_pipes(struct intel_display * display)3424 static u8 joiner_pipes(struct intel_display *display)
3425 {
3426 u8 pipes;
3427
3428 if (DISPLAY_VER(display) >= 12)
3429 pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D);
3430 else if (DISPLAY_VER(display) >= 11)
3431 pipes = BIT(PIPE_B) | BIT(PIPE_C);
3432 else
3433 pipes = 0;
3434
3435 return pipes & DISPLAY_RUNTIME_INFO(display)->pipe_mask;
3436 }
3437
transcoder_ddi_func_is_enabled(struct intel_display * display,enum transcoder cpu_transcoder)3438 static bool transcoder_ddi_func_is_enabled(struct intel_display *display,
3439 enum transcoder cpu_transcoder)
3440 {
3441 enum intel_display_power_domain power_domain;
3442 intel_wakeref_t wakeref;
3443 u32 tmp = 0;
3444
3445 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
3446
3447 with_intel_display_power_if_enabled(display, power_domain, wakeref)
3448 tmp = intel_de_read(display,
3449 TRANS_DDI_FUNC_CTL(display, cpu_transcoder));
3450
3451 return tmp & TRANS_DDI_FUNC_ENABLE;
3452 }
3453
enabled_uncompressed_joiner_pipes(struct intel_display * display,u8 * primary_pipes,u8 * secondary_pipes)3454 static void enabled_uncompressed_joiner_pipes(struct intel_display *display,
3455 u8 *primary_pipes, u8 *secondary_pipes)
3456 {
3457 struct intel_crtc *crtc;
3458
3459 *primary_pipes = 0;
3460 *secondary_pipes = 0;
3461
3462 if (!HAS_UNCOMPRESSED_JOINER(display))
3463 return;
3464
3465 for_each_intel_crtc_in_pipe_mask(display->drm, crtc,
3466 joiner_pipes(display)) {
3467 enum intel_display_power_domain power_domain;
3468 enum pipe pipe = crtc->pipe;
3469 intel_wakeref_t wakeref;
3470
3471 power_domain = POWER_DOMAIN_PIPE(pipe);
3472 with_intel_display_power_if_enabled(display, power_domain, wakeref) {
3473 u32 tmp = intel_de_read(display, ICL_PIPE_DSS_CTL1(pipe));
3474
3475 if (tmp & UNCOMPRESSED_JOINER_PRIMARY)
3476 *primary_pipes |= BIT(pipe);
3477 if (tmp & UNCOMPRESSED_JOINER_SECONDARY)
3478 *secondary_pipes |= BIT(pipe);
3479 }
3480 }
3481 }
3482
enabled_bigjoiner_pipes(struct intel_display * display,u8 * primary_pipes,u8 * secondary_pipes)3483 static void enabled_bigjoiner_pipes(struct intel_display *display,
3484 u8 *primary_pipes, u8 *secondary_pipes)
3485 {
3486 struct intel_crtc *crtc;
3487
3488 *primary_pipes = 0;
3489 *secondary_pipes = 0;
3490
3491 if (!HAS_BIGJOINER(display))
3492 return;
3493
3494 for_each_intel_crtc_in_pipe_mask(display->drm, crtc,
3495 joiner_pipes(display)) {
3496 enum intel_display_power_domain power_domain;
3497 enum pipe pipe = crtc->pipe;
3498 intel_wakeref_t wakeref;
3499
3500 power_domain = intel_dsc_power_domain(crtc, (enum transcoder)pipe);
3501 with_intel_display_power_if_enabled(display, power_domain, wakeref) {
3502 u32 tmp = intel_de_read(display, ICL_PIPE_DSS_CTL1(pipe));
3503
3504 if (!(tmp & BIG_JOINER_ENABLE))
3505 continue;
3506
3507 if (tmp & PRIMARY_BIG_JOINER_ENABLE)
3508 *primary_pipes |= BIT(pipe);
3509 else
3510 *secondary_pipes |= BIT(pipe);
3511 }
3512 }
3513 }
3514
expected_secondary_pipes(u8 primary_pipes,int num_pipes)3515 static u8 expected_secondary_pipes(u8 primary_pipes, int num_pipes)
3516 {
3517 u8 secondary_pipes = 0;
3518
3519 for (int i = 1; i < num_pipes; i++)
3520 secondary_pipes |= primary_pipes << i;
3521
3522 return secondary_pipes;
3523 }
3524
expected_uncompressed_joiner_secondary_pipes(u8 uncompjoiner_primary_pipes)3525 static u8 expected_uncompressed_joiner_secondary_pipes(u8 uncompjoiner_primary_pipes)
3526 {
3527 return expected_secondary_pipes(uncompjoiner_primary_pipes, 2);
3528 }
3529
expected_bigjoiner_secondary_pipes(u8 bigjoiner_primary_pipes)3530 static u8 expected_bigjoiner_secondary_pipes(u8 bigjoiner_primary_pipes)
3531 {
3532 return expected_secondary_pipes(bigjoiner_primary_pipes, 2);
3533 }
3534
get_joiner_primary_pipe(enum pipe pipe,u8 primary_pipes)3535 static u8 get_joiner_primary_pipe(enum pipe pipe, u8 primary_pipes)
3536 {
3537 primary_pipes &= GENMASK(pipe, 0);
3538
3539 return primary_pipes ? BIT(fls(primary_pipes) - 1) : 0;
3540 }
3541
expected_ultrajoiner_secondary_pipes(u8 ultrajoiner_primary_pipes)3542 static u8 expected_ultrajoiner_secondary_pipes(u8 ultrajoiner_primary_pipes)
3543 {
3544 return expected_secondary_pipes(ultrajoiner_primary_pipes, 4);
3545 }
3546
fixup_ultrajoiner_secondary_pipes(u8 ultrajoiner_primary_pipes,u8 ultrajoiner_secondary_pipes)3547 static u8 fixup_ultrajoiner_secondary_pipes(u8 ultrajoiner_primary_pipes,
3548 u8 ultrajoiner_secondary_pipes)
3549 {
3550 return ultrajoiner_secondary_pipes | ultrajoiner_primary_pipes << 3;
3551 }
3552
enabled_ultrajoiner_pipes(struct intel_display * display,u8 * primary_pipes,u8 * secondary_pipes)3553 static void enabled_ultrajoiner_pipes(struct intel_display *display,
3554 u8 *primary_pipes, u8 *secondary_pipes)
3555 {
3556 struct intel_crtc *crtc;
3557
3558 *primary_pipes = 0;
3559 *secondary_pipes = 0;
3560
3561 if (!HAS_ULTRAJOINER(display))
3562 return;
3563
3564 for_each_intel_crtc_in_pipe_mask(display->drm, crtc,
3565 joiner_pipes(display)) {
3566 enum intel_display_power_domain power_domain;
3567 enum pipe pipe = crtc->pipe;
3568 intel_wakeref_t wakeref;
3569
3570 power_domain = intel_dsc_power_domain(crtc, (enum transcoder)pipe);
3571 with_intel_display_power_if_enabled(display, power_domain, wakeref) {
3572 u32 tmp = intel_de_read(display, ICL_PIPE_DSS_CTL1(pipe));
3573
3574 if (!(tmp & ULTRA_JOINER_ENABLE))
3575 continue;
3576
3577 if (tmp & PRIMARY_ULTRA_JOINER_ENABLE)
3578 *primary_pipes |= BIT(pipe);
3579 else
3580 *secondary_pipes |= BIT(pipe);
3581 }
3582 }
3583 }
3584
enabled_joiner_pipes(struct intel_display * display,enum pipe pipe,u8 * primary_pipe,u8 * secondary_pipes)3585 static void enabled_joiner_pipes(struct intel_display *display,
3586 enum pipe pipe,
3587 u8 *primary_pipe, u8 *secondary_pipes)
3588 {
3589 u8 primary_ultrajoiner_pipes;
3590 u8 primary_uncompressed_joiner_pipes, primary_bigjoiner_pipes;
3591 u8 secondary_ultrajoiner_pipes;
3592 u8 secondary_uncompressed_joiner_pipes, secondary_bigjoiner_pipes;
3593 u8 ultrajoiner_pipes;
3594 u8 uncompressed_joiner_pipes, bigjoiner_pipes;
3595
3596 enabled_ultrajoiner_pipes(display, &primary_ultrajoiner_pipes,
3597 &secondary_ultrajoiner_pipes);
3598 /*
3599 * For some strange reason the last pipe in the set of four
3600 * shouldn't have ultrajoiner enable bit set in hardware.
3601 * Set the bit anyway to make life easier.
3602 */
3603 drm_WARN_ON(display->drm,
3604 expected_secondary_pipes(primary_ultrajoiner_pipes, 3) !=
3605 secondary_ultrajoiner_pipes);
3606 secondary_ultrajoiner_pipes =
3607 fixup_ultrajoiner_secondary_pipes(primary_ultrajoiner_pipes,
3608 secondary_ultrajoiner_pipes);
3609
3610 drm_WARN_ON(display->drm, (primary_ultrajoiner_pipes & secondary_ultrajoiner_pipes) != 0);
3611
3612 enabled_uncompressed_joiner_pipes(display, &primary_uncompressed_joiner_pipes,
3613 &secondary_uncompressed_joiner_pipes);
3614
3615 drm_WARN_ON(display->drm,
3616 (primary_uncompressed_joiner_pipes & secondary_uncompressed_joiner_pipes) != 0);
3617
3618 enabled_bigjoiner_pipes(display, &primary_bigjoiner_pipes,
3619 &secondary_bigjoiner_pipes);
3620
3621 drm_WARN_ON(display->drm,
3622 (primary_bigjoiner_pipes & secondary_bigjoiner_pipes) != 0);
3623
3624 ultrajoiner_pipes = primary_ultrajoiner_pipes | secondary_ultrajoiner_pipes;
3625 uncompressed_joiner_pipes = primary_uncompressed_joiner_pipes |
3626 secondary_uncompressed_joiner_pipes;
3627 bigjoiner_pipes = primary_bigjoiner_pipes | secondary_bigjoiner_pipes;
3628
3629 drm_WARN(display->drm, (ultrajoiner_pipes & bigjoiner_pipes) != ultrajoiner_pipes,
3630 "Ultrajoiner pipes(%#x) should be bigjoiner pipes(%#x)\n",
3631 ultrajoiner_pipes, bigjoiner_pipes);
3632
3633 drm_WARN(display->drm, secondary_ultrajoiner_pipes !=
3634 expected_ultrajoiner_secondary_pipes(primary_ultrajoiner_pipes),
3635 "Wrong secondary ultrajoiner pipes(expected %#x, current %#x)\n",
3636 expected_ultrajoiner_secondary_pipes(primary_ultrajoiner_pipes),
3637 secondary_ultrajoiner_pipes);
3638
3639 drm_WARN(display->drm, (uncompressed_joiner_pipes & bigjoiner_pipes) != 0,
3640 "Uncompressed joiner pipes(%#x) and bigjoiner pipes(%#x) can't intersect\n",
3641 uncompressed_joiner_pipes, bigjoiner_pipes);
3642
3643 drm_WARN(display->drm, secondary_bigjoiner_pipes !=
3644 expected_bigjoiner_secondary_pipes(primary_bigjoiner_pipes),
3645 "Wrong secondary bigjoiner pipes(expected %#x, current %#x)\n",
3646 expected_bigjoiner_secondary_pipes(primary_bigjoiner_pipes),
3647 secondary_bigjoiner_pipes);
3648
3649 drm_WARN(display->drm, secondary_uncompressed_joiner_pipes !=
3650 expected_uncompressed_joiner_secondary_pipes(primary_uncompressed_joiner_pipes),
3651 "Wrong secondary uncompressed joiner pipes(expected %#x, current %#x)\n",
3652 expected_uncompressed_joiner_secondary_pipes(primary_uncompressed_joiner_pipes),
3653 secondary_uncompressed_joiner_pipes);
3654
3655 *primary_pipe = 0;
3656 *secondary_pipes = 0;
3657
3658 if (ultrajoiner_pipes & BIT(pipe)) {
3659 *primary_pipe = get_joiner_primary_pipe(pipe, primary_ultrajoiner_pipes);
3660 *secondary_pipes = secondary_ultrajoiner_pipes &
3661 expected_ultrajoiner_secondary_pipes(*primary_pipe);
3662
3663 drm_WARN(display->drm,
3664 expected_ultrajoiner_secondary_pipes(*primary_pipe) !=
3665 *secondary_pipes,
3666 "Wrong ultrajoiner secondary pipes for primary_pipe %#x (expected %#x, current %#x)\n",
3667 *primary_pipe,
3668 expected_ultrajoiner_secondary_pipes(*primary_pipe),
3669 *secondary_pipes);
3670 return;
3671 }
3672
3673 if (uncompressed_joiner_pipes & BIT(pipe)) {
3674 *primary_pipe = get_joiner_primary_pipe(pipe, primary_uncompressed_joiner_pipes);
3675 *secondary_pipes = secondary_uncompressed_joiner_pipes &
3676 expected_uncompressed_joiner_secondary_pipes(*primary_pipe);
3677
3678 drm_WARN(display->drm,
3679 expected_uncompressed_joiner_secondary_pipes(*primary_pipe) !=
3680 *secondary_pipes,
3681 "Wrong uncompressed joiner secondary pipes for primary_pipe %#x (expected %#x, current %#x)\n",
3682 *primary_pipe,
3683 expected_uncompressed_joiner_secondary_pipes(*primary_pipe),
3684 *secondary_pipes);
3685 return;
3686 }
3687
3688 if (bigjoiner_pipes & BIT(pipe)) {
3689 *primary_pipe = get_joiner_primary_pipe(pipe, primary_bigjoiner_pipes);
3690 *secondary_pipes = secondary_bigjoiner_pipes &
3691 expected_bigjoiner_secondary_pipes(*primary_pipe);
3692
3693 drm_WARN(display->drm,
3694 expected_bigjoiner_secondary_pipes(*primary_pipe) !=
3695 *secondary_pipes,
3696 "Wrong bigjoiner secondary pipes for primary_pipe %#x (expected %#x, current %#x)\n",
3697 *primary_pipe,
3698 expected_bigjoiner_secondary_pipes(*primary_pipe),
3699 *secondary_pipes);
3700 return;
3701 }
3702 }
3703
hsw_panel_transcoders(struct intel_display * display)3704 static u8 hsw_panel_transcoders(struct intel_display *display)
3705 {
3706 u8 panel_transcoder_mask = BIT(TRANSCODER_EDP);
3707
3708 if (DISPLAY_VER(display) >= 11)
3709 panel_transcoder_mask |= BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
3710
3711 return panel_transcoder_mask;
3712 }
3713
hsw_enabled_transcoders(struct intel_crtc * crtc)3714 static u8 hsw_enabled_transcoders(struct intel_crtc *crtc)
3715 {
3716 struct intel_display *display = to_intel_display(crtc);
3717 u8 panel_transcoder_mask = hsw_panel_transcoders(display);
3718 enum transcoder cpu_transcoder;
3719 u8 primary_pipe, secondary_pipes;
3720 u8 enabled_transcoders = 0;
3721
3722 /*
3723 * XXX: Do intel_display_power_get_if_enabled before reading this (for
3724 * consistency and less surprising code; it's in always on power).
3725 */
3726 for_each_cpu_transcoder_masked(display, cpu_transcoder,
3727 panel_transcoder_mask) {
3728 enum intel_display_power_domain power_domain;
3729 intel_wakeref_t wakeref;
3730 enum pipe trans_pipe;
3731 u32 tmp = 0;
3732
3733 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
3734 with_intel_display_power_if_enabled(display, power_domain, wakeref)
3735 tmp = intel_de_read(display,
3736 TRANS_DDI_FUNC_CTL(display, cpu_transcoder));
3737
3738 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
3739 continue;
3740
3741 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
3742 default:
3743 drm_WARN(display->drm, 1,
3744 "unknown pipe linked to transcoder %s\n",
3745 transcoder_name(cpu_transcoder));
3746 fallthrough;
3747 case TRANS_DDI_EDP_INPUT_A_ONOFF:
3748 case TRANS_DDI_EDP_INPUT_A_ON:
3749 trans_pipe = PIPE_A;
3750 break;
3751 case TRANS_DDI_EDP_INPUT_B_ONOFF:
3752 trans_pipe = PIPE_B;
3753 break;
3754 case TRANS_DDI_EDP_INPUT_C_ONOFF:
3755 trans_pipe = PIPE_C;
3756 break;
3757 case TRANS_DDI_EDP_INPUT_D_ONOFF:
3758 trans_pipe = PIPE_D;
3759 break;
3760 }
3761
3762 if (trans_pipe == crtc->pipe)
3763 enabled_transcoders |= BIT(cpu_transcoder);
3764 }
3765
3766 /* single pipe or joiner primary */
3767 cpu_transcoder = (enum transcoder) crtc->pipe;
3768 if (transcoder_ddi_func_is_enabled(display, cpu_transcoder))
3769 enabled_transcoders |= BIT(cpu_transcoder);
3770
3771 /* joiner secondary -> consider the primary pipe's transcoder as well */
3772 enabled_joiner_pipes(display, crtc->pipe, &primary_pipe, &secondary_pipes);
3773 if (secondary_pipes & BIT(crtc->pipe)) {
3774 cpu_transcoder = (enum transcoder)ffs(primary_pipe) - 1;
3775 if (transcoder_ddi_func_is_enabled(display, cpu_transcoder))
3776 enabled_transcoders |= BIT(cpu_transcoder);
3777 }
3778
3779 return enabled_transcoders;
3780 }
3781
has_edp_transcoders(u8 enabled_transcoders)3782 static bool has_edp_transcoders(u8 enabled_transcoders)
3783 {
3784 return enabled_transcoders & BIT(TRANSCODER_EDP);
3785 }
3786
has_dsi_transcoders(u8 enabled_transcoders)3787 static bool has_dsi_transcoders(u8 enabled_transcoders)
3788 {
3789 return enabled_transcoders & (BIT(TRANSCODER_DSI_0) |
3790 BIT(TRANSCODER_DSI_1));
3791 }
3792
has_pipe_transcoders(u8 enabled_transcoders)3793 static bool has_pipe_transcoders(u8 enabled_transcoders)
3794 {
3795 return enabled_transcoders & ~(BIT(TRANSCODER_EDP) |
3796 BIT(TRANSCODER_DSI_0) |
3797 BIT(TRANSCODER_DSI_1));
3798 }
3799
assert_enabled_transcoders(struct intel_display * display,u8 enabled_transcoders)3800 static void assert_enabled_transcoders(struct intel_display *display,
3801 u8 enabled_transcoders)
3802 {
3803 /* Only one type of transcoder please */
3804 drm_WARN_ON(display->drm,
3805 has_edp_transcoders(enabled_transcoders) +
3806 has_dsi_transcoders(enabled_transcoders) +
3807 has_pipe_transcoders(enabled_transcoders) > 1);
3808
3809 /* Only DSI transcoders can be ganged */
3810 drm_WARN_ON(display->drm,
3811 !has_dsi_transcoders(enabled_transcoders) &&
3812 !is_power_of_2(enabled_transcoders));
3813 }
3814
hsw_get_transcoder_state(struct intel_crtc * crtc,struct intel_crtc_state * pipe_config,struct intel_display_power_domain_set * power_domain_set)3815 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
3816 struct intel_crtc_state *pipe_config,
3817 struct intel_display_power_domain_set *power_domain_set)
3818 {
3819 struct intel_display *display = to_intel_display(crtc);
3820 unsigned long enabled_transcoders;
3821 u32 tmp;
3822
3823 enabled_transcoders = hsw_enabled_transcoders(crtc);
3824 if (!enabled_transcoders)
3825 return false;
3826
3827 assert_enabled_transcoders(display, enabled_transcoders);
3828
3829 /*
3830 * With the exception of DSI we should only ever have
3831 * a single enabled transcoder. With DSI let's just
3832 * pick the first one.
3833 */
3834 pipe_config->cpu_transcoder = ffs(enabled_transcoders) - 1;
3835
3836 if (!intel_display_power_get_in_set_if_enabled(display, power_domain_set,
3837 POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
3838 return false;
3839
3840 if (hsw_panel_transcoders(display) & BIT(pipe_config->cpu_transcoder)) {
3841 tmp = intel_de_read(display,
3842 TRANS_DDI_FUNC_CTL(display, pipe_config->cpu_transcoder));
3843
3844 if ((tmp & TRANS_DDI_EDP_INPUT_MASK) == TRANS_DDI_EDP_INPUT_A_ONOFF)
3845 pipe_config->pch_pfit.force_thru = true;
3846 }
3847
3848 tmp = intel_de_read(display,
3849 TRANSCONF(display, pipe_config->cpu_transcoder));
3850
3851 return tmp & TRANSCONF_ENABLE;
3852 }
3853
bxt_get_dsi_transcoder_state(struct intel_crtc * crtc,struct intel_crtc_state * pipe_config,struct intel_display_power_domain_set * power_domain_set)3854 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
3855 struct intel_crtc_state *pipe_config,
3856 struct intel_display_power_domain_set *power_domain_set)
3857 {
3858 struct intel_display *display = to_intel_display(crtc);
3859 enum transcoder cpu_transcoder;
3860 enum port port;
3861 u32 tmp;
3862
3863 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
3864 if (port == PORT_A)
3865 cpu_transcoder = TRANSCODER_DSI_A;
3866 else
3867 cpu_transcoder = TRANSCODER_DSI_C;
3868
3869 if (!intel_display_power_get_in_set_if_enabled(display, power_domain_set,
3870 POWER_DOMAIN_TRANSCODER(cpu_transcoder)))
3871 continue;
3872
3873 /*
3874 * The PLL needs to be enabled with a valid divider
3875 * configuration, otherwise accessing DSI registers will hang
3876 * the machine. See BSpec North Display Engine
3877 * registers/MIPI[BXT]. We can break out here early, since we
3878 * need the same DSI PLL to be enabled for both DSI ports.
3879 */
3880 if (!bxt_dsi_pll_is_enabled(display))
3881 break;
3882
3883 /* XXX: this works for video mode only */
3884 tmp = intel_de_read(display, BXT_MIPI_PORT_CTRL(port));
3885 if (!(tmp & DPI_ENABLE))
3886 continue;
3887
3888 tmp = intel_de_read(display, MIPI_CTRL(display, port));
3889 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
3890 continue;
3891
3892 pipe_config->cpu_transcoder = cpu_transcoder;
3893 break;
3894 }
3895
3896 return transcoder_is_dsi(pipe_config->cpu_transcoder);
3897 }
3898
intel_joiner_get_config(struct intel_crtc_state * crtc_state)3899 static void intel_joiner_get_config(struct intel_crtc_state *crtc_state)
3900 {
3901 struct intel_display *display = to_intel_display(crtc_state);
3902 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3903 u8 primary_pipe, secondary_pipes;
3904 enum pipe pipe = crtc->pipe;
3905
3906 enabled_joiner_pipes(display, pipe, &primary_pipe, &secondary_pipes);
3907
3908 if (((primary_pipe | secondary_pipes) & BIT(pipe)) == 0)
3909 return;
3910
3911 crtc_state->joiner_pipes = primary_pipe | secondary_pipes;
3912 }
3913
hsw_get_pipe_config(struct intel_crtc * crtc,struct intel_crtc_state * pipe_config)3914 static bool hsw_get_pipe_config(struct intel_crtc *crtc,
3915 struct intel_crtc_state *pipe_config)
3916 {
3917 struct intel_display *display = to_intel_display(crtc);
3918 bool active;
3919 u32 tmp;
3920
3921 if (!intel_display_power_get_in_set_if_enabled(display, &crtc->hw_readout_power_domains,
3922 POWER_DOMAIN_PIPE(crtc->pipe)))
3923 return false;
3924
3925 active = hsw_get_transcoder_state(crtc, pipe_config, &crtc->hw_readout_power_domains);
3926
3927 if ((display->platform.geminilake || display->platform.broxton) &&
3928 bxt_get_dsi_transcoder_state(crtc, pipe_config, &crtc->hw_readout_power_domains)) {
3929 drm_WARN_ON(display->drm, active);
3930 active = true;
3931 }
3932
3933 if (!active)
3934 goto out;
3935
3936 intel_joiner_get_config(pipe_config);
3937 intel_dsc_get_config(pipe_config);
3938
3939 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
3940 DISPLAY_VER(display) >= 11)
3941 intel_get_transcoder_timings(crtc, pipe_config);
3942
3943 if (transcoder_has_vrr(pipe_config))
3944 intel_vrr_get_config(pipe_config);
3945
3946 intel_get_pipe_src_size(crtc, pipe_config);
3947
3948 if (display->platform.haswell) {
3949 u32 tmp = intel_de_read(display,
3950 TRANSCONF(display, pipe_config->cpu_transcoder));
3951
3952 if (tmp & TRANSCONF_OUTPUT_COLORSPACE_YUV_HSW)
3953 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
3954 else
3955 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
3956 } else {
3957 pipe_config->output_format =
3958 bdw_get_pipe_misc_output_format(crtc);
3959 }
3960
3961 pipe_config->sink_format = pipe_config->output_format;
3962
3963 intel_color_get_config(pipe_config);
3964
3965 tmp = intel_de_read(display, WM_LINETIME(crtc->pipe));
3966 pipe_config->linetime = REG_FIELD_GET(HSW_LINETIME_MASK, tmp);
3967 if (display->platform.broadwell || display->platform.haswell)
3968 pipe_config->ips_linetime =
3969 REG_FIELD_GET(HSW_IPS_LINETIME_MASK, tmp);
3970
3971 if (intel_display_power_get_in_set_if_enabled(display, &crtc->hw_readout_power_domains,
3972 POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe))) {
3973 if (DISPLAY_VER(display) >= 9)
3974 skl_scaler_get_config(pipe_config);
3975 else
3976 ilk_pfit_get_config(pipe_config);
3977 }
3978
3979 hsw_ips_get_config(pipe_config);
3980
3981 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
3982 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
3983 pipe_config->pixel_multiplier =
3984 intel_de_read(display,
3985 TRANS_MULT(display, pipe_config->cpu_transcoder)) + 1;
3986 } else {
3987 pipe_config->pixel_multiplier = 1;
3988 }
3989
3990 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
3991 tmp = intel_de_read(display, CHICKEN_TRANS(display, pipe_config->cpu_transcoder));
3992
3993 pipe_config->framestart_delay = REG_FIELD_GET(HSW_FRAME_START_DELAY_MASK, tmp) + 1;
3994 } else {
3995 /* no idea if this is correct */
3996 pipe_config->framestart_delay = 1;
3997 }
3998
3999 out:
4000 intel_display_power_put_all_in_set(display, &crtc->hw_readout_power_domains);
4001
4002 return active;
4003 }
4004
intel_crtc_get_pipe_config(struct intel_crtc_state * crtc_state)4005 bool intel_crtc_get_pipe_config(struct intel_crtc_state *crtc_state)
4006 {
4007 struct intel_display *display = to_intel_display(crtc_state);
4008 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4009
4010 if (!display->funcs.display->get_pipe_config(crtc, crtc_state))
4011 return false;
4012
4013 crtc_state->hw.active = true;
4014
4015 intel_crtc_readout_derived_state(crtc_state);
4016
4017 return true;
4018 }
4019
intel_dotclock_calculate(int link_freq,const struct intel_link_m_n * m_n)4020 int intel_dotclock_calculate(int link_freq,
4021 const struct intel_link_m_n *m_n)
4022 {
4023 /*
4024 * The calculation for the data clock -> pixel clock is:
4025 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
4026 * But we want to avoid losing precision if possible, so:
4027 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
4028 *
4029 * and for link freq (10kbs units) -> pixel clock it is:
4030 * link_symbol_clock = link_freq * 10 / link_symbol_size
4031 * pixel_clock = (m * link_symbol_clock) / n
4032 * or for more precision:
4033 * pixel_clock = (m * link_freq * 10) / (n * link_symbol_size)
4034 */
4035
4036 if (!m_n->link_n)
4037 return 0;
4038
4039 return DIV_ROUND_UP_ULL(mul_u32_u32(m_n->link_m, link_freq * 10),
4040 m_n->link_n * intel_dp_link_symbol_size(link_freq));
4041 }
4042
intel_crtc_dotclock(const struct intel_crtc_state * pipe_config)4043 int intel_crtc_dotclock(const struct intel_crtc_state *pipe_config)
4044 {
4045 int dotclock;
4046
4047 if (intel_crtc_has_dp_encoder(pipe_config))
4048 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
4049 &pipe_config->dp_m_n);
4050 else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp > 24)
4051 dotclock = DIV_ROUND_CLOSEST(pipe_config->port_clock * 24,
4052 pipe_config->pipe_bpp);
4053 else
4054 dotclock = pipe_config->port_clock;
4055
4056 if (pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 &&
4057 !intel_crtc_has_dp_encoder(pipe_config))
4058 dotclock *= 2;
4059
4060 if (pipe_config->pixel_multiplier)
4061 dotclock /= pipe_config->pixel_multiplier;
4062
4063 return dotclock;
4064 }
4065
4066 /* Returns the currently programmed mode of the given encoder. */
4067 struct drm_display_mode *
intel_encoder_current_mode(struct intel_encoder * encoder)4068 intel_encoder_current_mode(struct intel_encoder *encoder)
4069 {
4070 struct intel_display *display = to_intel_display(encoder);
4071 struct intel_crtc_state *crtc_state;
4072 struct drm_display_mode *mode;
4073 struct intel_crtc *crtc;
4074 enum pipe pipe;
4075
4076 if (!encoder->get_hw_state(encoder, &pipe))
4077 return NULL;
4078
4079 crtc = intel_crtc_for_pipe(display, pipe);
4080
4081 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
4082 if (!mode)
4083 return NULL;
4084
4085 crtc_state = intel_crtc_state_alloc(crtc);
4086 if (!crtc_state) {
4087 kfree(mode);
4088 return NULL;
4089 }
4090
4091 if (!intel_crtc_get_pipe_config(crtc_state)) {
4092 intel_crtc_destroy_state(&crtc->base, &crtc_state->uapi);
4093 kfree(mode);
4094 return NULL;
4095 }
4096
4097 intel_encoder_get_config(encoder, crtc_state);
4098
4099 intel_mode_from_crtc_timings(mode, &crtc_state->hw.adjusted_mode);
4100
4101 intel_crtc_destroy_state(&crtc->base, &crtc_state->uapi);
4102
4103 return mode;
4104 }
4105
encoders_cloneable(const struct intel_encoder * a,const struct intel_encoder * b)4106 static bool encoders_cloneable(const struct intel_encoder *a,
4107 const struct intel_encoder *b)
4108 {
4109 /* masks could be asymmetric, so check both ways */
4110 return a == b || (a->cloneable & BIT(b->type) &&
4111 b->cloneable & BIT(a->type));
4112 }
4113
check_single_encoder_cloning(struct intel_atomic_state * state,struct intel_crtc * crtc,struct intel_encoder * encoder)4114 static bool check_single_encoder_cloning(struct intel_atomic_state *state,
4115 struct intel_crtc *crtc,
4116 struct intel_encoder *encoder)
4117 {
4118 struct intel_encoder *source_encoder;
4119 struct drm_connector *connector;
4120 struct drm_connector_state *connector_state;
4121 int i;
4122
4123 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4124 if (connector_state->crtc != &crtc->base)
4125 continue;
4126
4127 source_encoder =
4128 to_intel_encoder(connector_state->best_encoder);
4129 if (!encoders_cloneable(encoder, source_encoder))
4130 return false;
4131 }
4132
4133 return true;
4134 }
4135
hsw_linetime_wm(const struct intel_crtc_state * crtc_state)4136 static u16 hsw_linetime_wm(const struct intel_crtc_state *crtc_state)
4137 {
4138 const struct drm_display_mode *pipe_mode =
4139 &crtc_state->hw.pipe_mode;
4140 int linetime_wm;
4141
4142 if (!crtc_state->hw.enable)
4143 return 0;
4144
4145 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
4146 pipe_mode->crtc_clock);
4147
4148 return min(linetime_wm, 0x1ff);
4149 }
4150
hsw_ips_linetime_wm(const struct intel_crtc_state * crtc_state,const struct intel_cdclk_state * cdclk_state)4151 static u16 hsw_ips_linetime_wm(const struct intel_crtc_state *crtc_state,
4152 const struct intel_cdclk_state *cdclk_state)
4153 {
4154 const struct drm_display_mode *pipe_mode =
4155 &crtc_state->hw.pipe_mode;
4156 int linetime_wm;
4157
4158 if (!crtc_state->hw.enable)
4159 return 0;
4160
4161 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
4162 cdclk_state->logical.cdclk);
4163
4164 return min(linetime_wm, 0x1ff);
4165 }
4166
skl_linetime_wm(const struct intel_crtc_state * crtc_state)4167 static u16 skl_linetime_wm(const struct intel_crtc_state *crtc_state)
4168 {
4169 struct intel_display *display = to_intel_display(crtc_state);
4170 const struct drm_display_mode *pipe_mode =
4171 &crtc_state->hw.pipe_mode;
4172 int linetime_wm;
4173
4174 if (!crtc_state->hw.enable)
4175 return 0;
4176
4177 linetime_wm = DIV_ROUND_UP(pipe_mode->crtc_htotal * 1000 * 8,
4178 crtc_state->pixel_rate);
4179
4180 /* Display WA #1135: BXT:ALL GLK:ALL */
4181 if ((display->platform.geminilake || display->platform.broxton) &&
4182 skl_watermark_ipc_enabled(display))
4183 linetime_wm /= 2;
4184
4185 return min(linetime_wm, 0x1ff);
4186 }
4187
hsw_compute_linetime_wm(struct intel_atomic_state * state,struct intel_crtc * crtc)4188 static int hsw_compute_linetime_wm(struct intel_atomic_state *state,
4189 struct intel_crtc *crtc)
4190 {
4191 struct intel_display *display = to_intel_display(state);
4192 struct intel_crtc_state *crtc_state =
4193 intel_atomic_get_new_crtc_state(state, crtc);
4194 const struct intel_cdclk_state *cdclk_state;
4195
4196 if (DISPLAY_VER(display) >= 9)
4197 crtc_state->linetime = skl_linetime_wm(crtc_state);
4198 else
4199 crtc_state->linetime = hsw_linetime_wm(crtc_state);
4200
4201 if (!hsw_crtc_supports_ips(crtc))
4202 return 0;
4203
4204 cdclk_state = intel_atomic_get_cdclk_state(state);
4205 if (IS_ERR(cdclk_state))
4206 return PTR_ERR(cdclk_state);
4207
4208 crtc_state->ips_linetime = hsw_ips_linetime_wm(crtc_state,
4209 cdclk_state);
4210
4211 return 0;
4212 }
4213
intel_crtc_atomic_check(struct intel_atomic_state * state,struct intel_crtc * crtc)4214 static int intel_crtc_atomic_check(struct intel_atomic_state *state,
4215 struct intel_crtc *crtc)
4216 {
4217 struct intel_display *display = to_intel_display(crtc);
4218 struct intel_crtc_state *crtc_state =
4219 intel_atomic_get_new_crtc_state(state, crtc);
4220 int ret;
4221
4222 if (DISPLAY_VER(display) < 5 && !display->platform.g4x &&
4223 intel_crtc_needs_modeset(crtc_state) &&
4224 !crtc_state->hw.active)
4225 crtc_state->update_wm_post = true;
4226
4227 if (intel_crtc_needs_modeset(crtc_state)) {
4228 ret = intel_dpll_crtc_get_shared_dpll(state, crtc);
4229 if (ret)
4230 return ret;
4231 }
4232
4233 ret = intel_color_check(state, crtc);
4234 if (ret)
4235 return ret;
4236
4237 ret = intel_wm_compute(state, crtc);
4238 if (ret) {
4239 drm_dbg_kms(display->drm,
4240 "[CRTC:%d:%s] watermarks are invalid\n",
4241 crtc->base.base.id, crtc->base.name);
4242 return ret;
4243 }
4244
4245 if (DISPLAY_VER(display) >= 9) {
4246 if (intel_crtc_needs_modeset(crtc_state) ||
4247 intel_crtc_needs_fastset(crtc_state)) {
4248 ret = skl_update_scaler_crtc(crtc_state);
4249 if (ret)
4250 return ret;
4251 }
4252
4253 ret = intel_atomic_setup_scalers(state, crtc);
4254 if (ret)
4255 return ret;
4256 }
4257
4258 if (HAS_IPS(display)) {
4259 ret = hsw_ips_compute_config(state, crtc);
4260 if (ret)
4261 return ret;
4262 }
4263
4264 if (DISPLAY_VER(display) >= 9 ||
4265 display->platform.broadwell || display->platform.haswell) {
4266 ret = hsw_compute_linetime_wm(state, crtc);
4267 if (ret)
4268 return ret;
4269
4270 }
4271
4272 ret = intel_psr2_sel_fetch_update(state, crtc);
4273 if (ret)
4274 return ret;
4275
4276 return 0;
4277 }
4278
4279 static int
compute_sink_pipe_bpp(const struct drm_connector_state * conn_state,struct intel_crtc_state * crtc_state)4280 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
4281 struct intel_crtc_state *crtc_state)
4282 {
4283 struct intel_display *display = to_intel_display(crtc_state);
4284 struct drm_connector *connector = conn_state->connector;
4285 const struct drm_display_info *info = &connector->display_info;
4286 int bpp;
4287
4288 switch (conn_state->max_bpc) {
4289 case 6 ... 7:
4290 bpp = 6 * 3;
4291 break;
4292 case 8 ... 9:
4293 bpp = 8 * 3;
4294 break;
4295 case 10 ... 11:
4296 bpp = 10 * 3;
4297 break;
4298 case 12 ... 16:
4299 bpp = 12 * 3;
4300 break;
4301 default:
4302 MISSING_CASE(conn_state->max_bpc);
4303 return -EINVAL;
4304 }
4305
4306 if (bpp < crtc_state->pipe_bpp) {
4307 drm_dbg_kms(display->drm,
4308 "[CONNECTOR:%d:%s] Limiting display bpp to %d "
4309 "(EDID bpp %d, max requested bpp %d, max platform bpp %d)\n",
4310 connector->base.id, connector->name,
4311 bpp, 3 * info->bpc,
4312 3 * conn_state->max_requested_bpc,
4313 crtc_state->pipe_bpp);
4314
4315 crtc_state->pipe_bpp = bpp;
4316 }
4317
4318 return 0;
4319 }
4320
4321 static int
compute_baseline_pipe_bpp(struct intel_atomic_state * state,struct intel_crtc * crtc)4322 compute_baseline_pipe_bpp(struct intel_atomic_state *state,
4323 struct intel_crtc *crtc)
4324 {
4325 struct intel_display *display = to_intel_display(crtc);
4326 struct intel_crtc_state *crtc_state =
4327 intel_atomic_get_new_crtc_state(state, crtc);
4328 struct drm_connector *connector;
4329 struct drm_connector_state *connector_state;
4330 int bpp, i;
4331
4332 if (display->platform.g4x || display->platform.valleyview ||
4333 display->platform.cherryview)
4334 bpp = 10*3;
4335 else if (DISPLAY_VER(display) >= 5)
4336 bpp = 12*3;
4337 else
4338 bpp = 8*3;
4339
4340 crtc_state->pipe_bpp = bpp;
4341
4342 /* Clamp display bpp to connector max bpp */
4343 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4344 int ret;
4345
4346 if (connector_state->crtc != &crtc->base)
4347 continue;
4348
4349 ret = compute_sink_pipe_bpp(connector_state, crtc_state);
4350 if (ret)
4351 return ret;
4352 }
4353
4354 return 0;
4355 }
4356
check_digital_port_conflicts(struct intel_atomic_state * state)4357 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
4358 {
4359 struct intel_display *display = to_intel_display(state);
4360 struct drm_connector *connector;
4361 struct drm_connector_list_iter conn_iter;
4362 unsigned int used_ports = 0;
4363 unsigned int used_mst_ports = 0;
4364 bool ret = true;
4365
4366 /*
4367 * We're going to peek into connector->state,
4368 * hence connection_mutex must be held.
4369 */
4370 drm_modeset_lock_assert_held(&display->drm->mode_config.connection_mutex);
4371
4372 /*
4373 * Walk the connector list instead of the encoder
4374 * list to detect the problem on ddi platforms
4375 * where there's just one encoder per digital port.
4376 */
4377 drm_connector_list_iter_begin(display->drm, &conn_iter);
4378 drm_for_each_connector_iter(connector, &conn_iter) {
4379 struct drm_connector_state *connector_state;
4380 struct intel_encoder *encoder;
4381
4382 connector_state =
4383 drm_atomic_get_new_connector_state(&state->base,
4384 connector);
4385 if (!connector_state)
4386 connector_state = connector->state;
4387
4388 if (!connector_state->best_encoder)
4389 continue;
4390
4391 encoder = to_intel_encoder(connector_state->best_encoder);
4392
4393 drm_WARN_ON(display->drm, !connector_state->crtc);
4394
4395 switch (encoder->type) {
4396 case INTEL_OUTPUT_DDI:
4397 if (drm_WARN_ON(display->drm, !HAS_DDI(display)))
4398 break;
4399 fallthrough;
4400 case INTEL_OUTPUT_DP:
4401 case INTEL_OUTPUT_HDMI:
4402 case INTEL_OUTPUT_EDP:
4403 /* the same port mustn't appear more than once */
4404 if (used_ports & BIT(encoder->port))
4405 ret = false;
4406
4407 used_ports |= BIT(encoder->port);
4408 break;
4409 case INTEL_OUTPUT_DP_MST:
4410 used_mst_ports |=
4411 1 << encoder->port;
4412 break;
4413 default:
4414 break;
4415 }
4416 }
4417 drm_connector_list_iter_end(&conn_iter);
4418
4419 /* can't mix MST and SST/HDMI on the same port */
4420 if (used_ports & used_mst_ports)
4421 return false;
4422
4423 return ret;
4424 }
4425
4426 static void
intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_atomic_state * state,struct intel_crtc * crtc)4427 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_atomic_state *state,
4428 struct intel_crtc *crtc)
4429 {
4430 struct intel_crtc_state *crtc_state =
4431 intel_atomic_get_new_crtc_state(state, crtc);
4432
4433 WARN_ON(intel_crtc_is_joiner_secondary(crtc_state));
4434
4435 drm_property_replace_blob(&crtc_state->hw.degamma_lut,
4436 crtc_state->uapi.degamma_lut);
4437 drm_property_replace_blob(&crtc_state->hw.gamma_lut,
4438 crtc_state->uapi.gamma_lut);
4439 drm_property_replace_blob(&crtc_state->hw.ctm,
4440 crtc_state->uapi.ctm);
4441 }
4442
4443 static void
intel_crtc_copy_uapi_to_hw_state_modeset(struct intel_atomic_state * state,struct intel_crtc * crtc)4444 intel_crtc_copy_uapi_to_hw_state_modeset(struct intel_atomic_state *state,
4445 struct intel_crtc *crtc)
4446 {
4447 struct intel_crtc_state *crtc_state =
4448 intel_atomic_get_new_crtc_state(state, crtc);
4449
4450 WARN_ON(intel_crtc_is_joiner_secondary(crtc_state));
4451
4452 crtc_state->hw.enable = crtc_state->uapi.enable;
4453 crtc_state->hw.active = crtc_state->uapi.active;
4454 drm_mode_copy(&crtc_state->hw.mode,
4455 &crtc_state->uapi.mode);
4456 drm_mode_copy(&crtc_state->hw.adjusted_mode,
4457 &crtc_state->uapi.adjusted_mode);
4458 crtc_state->hw.scaling_filter = crtc_state->uapi.scaling_filter;
4459
4460 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc);
4461 }
4462
4463 static void
copy_joiner_crtc_state_nomodeset(struct intel_atomic_state * state,struct intel_crtc * secondary_crtc)4464 copy_joiner_crtc_state_nomodeset(struct intel_atomic_state *state,
4465 struct intel_crtc *secondary_crtc)
4466 {
4467 struct intel_crtc_state *secondary_crtc_state =
4468 intel_atomic_get_new_crtc_state(state, secondary_crtc);
4469 struct intel_crtc *primary_crtc = intel_primary_crtc(secondary_crtc_state);
4470 const struct intel_crtc_state *primary_crtc_state =
4471 intel_atomic_get_new_crtc_state(state, primary_crtc);
4472
4473 drm_property_replace_blob(&secondary_crtc_state->hw.degamma_lut,
4474 primary_crtc_state->hw.degamma_lut);
4475 drm_property_replace_blob(&secondary_crtc_state->hw.gamma_lut,
4476 primary_crtc_state->hw.gamma_lut);
4477 drm_property_replace_blob(&secondary_crtc_state->hw.ctm,
4478 primary_crtc_state->hw.ctm);
4479
4480 secondary_crtc_state->uapi.color_mgmt_changed = primary_crtc_state->uapi.color_mgmt_changed;
4481 }
4482
4483 static int
copy_joiner_crtc_state_modeset(struct intel_atomic_state * state,struct intel_crtc * secondary_crtc)4484 copy_joiner_crtc_state_modeset(struct intel_atomic_state *state,
4485 struct intel_crtc *secondary_crtc)
4486 {
4487 struct intel_crtc_state *secondary_crtc_state =
4488 intel_atomic_get_new_crtc_state(state, secondary_crtc);
4489 struct intel_crtc *primary_crtc = intel_primary_crtc(secondary_crtc_state);
4490 const struct intel_crtc_state *primary_crtc_state =
4491 intel_atomic_get_new_crtc_state(state, primary_crtc);
4492 struct intel_crtc_state *saved_state;
4493
4494 WARN_ON(primary_crtc_state->joiner_pipes !=
4495 secondary_crtc_state->joiner_pipes);
4496
4497 saved_state = kmemdup(primary_crtc_state, sizeof(*saved_state), GFP_KERNEL);
4498 if (!saved_state)
4499 return -ENOMEM;
4500
4501 /* preserve some things from the slave's original crtc state */
4502 saved_state->uapi = secondary_crtc_state->uapi;
4503 saved_state->scaler_state = secondary_crtc_state->scaler_state;
4504 saved_state->shared_dpll = secondary_crtc_state->shared_dpll;
4505 saved_state->crc_enabled = secondary_crtc_state->crc_enabled;
4506
4507 intel_crtc_free_hw_state(secondary_crtc_state);
4508 if (secondary_crtc_state->dp_tunnel_ref.tunnel)
4509 drm_dp_tunnel_ref_put(&secondary_crtc_state->dp_tunnel_ref);
4510 memcpy(secondary_crtc_state, saved_state, sizeof(*secondary_crtc_state));
4511 kfree(saved_state);
4512
4513 /* Re-init hw state */
4514 memset(&secondary_crtc_state->hw, 0, sizeof(secondary_crtc_state->hw));
4515 secondary_crtc_state->hw.enable = primary_crtc_state->hw.enable;
4516 secondary_crtc_state->hw.active = primary_crtc_state->hw.active;
4517 drm_mode_copy(&secondary_crtc_state->hw.mode,
4518 &primary_crtc_state->hw.mode);
4519 drm_mode_copy(&secondary_crtc_state->hw.pipe_mode,
4520 &primary_crtc_state->hw.pipe_mode);
4521 drm_mode_copy(&secondary_crtc_state->hw.adjusted_mode,
4522 &primary_crtc_state->hw.adjusted_mode);
4523 secondary_crtc_state->hw.scaling_filter = primary_crtc_state->hw.scaling_filter;
4524
4525 if (primary_crtc_state->dp_tunnel_ref.tunnel)
4526 drm_dp_tunnel_ref_get(primary_crtc_state->dp_tunnel_ref.tunnel,
4527 &secondary_crtc_state->dp_tunnel_ref);
4528
4529 copy_joiner_crtc_state_nomodeset(state, secondary_crtc);
4530
4531 secondary_crtc_state->uapi.mode_changed = primary_crtc_state->uapi.mode_changed;
4532 secondary_crtc_state->uapi.connectors_changed = primary_crtc_state->uapi.connectors_changed;
4533 secondary_crtc_state->uapi.active_changed = primary_crtc_state->uapi.active_changed;
4534
4535 WARN_ON(primary_crtc_state->joiner_pipes !=
4536 secondary_crtc_state->joiner_pipes);
4537
4538 return 0;
4539 }
4540
4541 static int
intel_crtc_prepare_cleared_state(struct intel_atomic_state * state,struct intel_crtc * crtc)4542 intel_crtc_prepare_cleared_state(struct intel_atomic_state *state,
4543 struct intel_crtc *crtc)
4544 {
4545 struct intel_display *display = to_intel_display(state);
4546 struct intel_crtc_state *crtc_state =
4547 intel_atomic_get_new_crtc_state(state, crtc);
4548 struct intel_crtc_state *saved_state;
4549
4550 saved_state = intel_crtc_state_alloc(crtc);
4551 if (!saved_state)
4552 return -ENOMEM;
4553
4554 /* free the old crtc_state->hw members */
4555 intel_crtc_free_hw_state(crtc_state);
4556
4557 intel_dp_tunnel_atomic_clear_stream_bw(state, crtc_state);
4558
4559 /* FIXME: before the switch to atomic started, a new pipe_config was
4560 * kzalloc'd. Code that depends on any field being zero should be
4561 * fixed, so that the crtc_state can be safely duplicated. For now,
4562 * only fields that are know to not cause problems are preserved. */
4563
4564 saved_state->uapi = crtc_state->uapi;
4565 saved_state->inherited = crtc_state->inherited;
4566 saved_state->scaler_state = crtc_state->scaler_state;
4567 saved_state->shared_dpll = crtc_state->shared_dpll;
4568 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
4569 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
4570 sizeof(saved_state->icl_port_dplls));
4571 saved_state->crc_enabled = crtc_state->crc_enabled;
4572 if (display->platform.g4x ||
4573 display->platform.valleyview || display->platform.cherryview)
4574 saved_state->wm = crtc_state->wm;
4575
4576 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
4577 kfree(saved_state);
4578
4579 intel_crtc_copy_uapi_to_hw_state_modeset(state, crtc);
4580
4581 return 0;
4582 }
4583
4584 static int
intel_modeset_pipe_config(struct intel_atomic_state * state,struct intel_crtc * crtc,const struct intel_link_bw_limits * limits)4585 intel_modeset_pipe_config(struct intel_atomic_state *state,
4586 struct intel_crtc *crtc,
4587 const struct intel_link_bw_limits *limits)
4588 {
4589 struct intel_display *display = to_intel_display(crtc);
4590 struct intel_crtc_state *crtc_state =
4591 intel_atomic_get_new_crtc_state(state, crtc);
4592 struct drm_connector *connector;
4593 struct drm_connector_state *connector_state;
4594 int pipe_src_w, pipe_src_h;
4595 int base_bpp, ret, i;
4596
4597 crtc_state->cpu_transcoder = (enum transcoder) crtc->pipe;
4598
4599 crtc_state->framestart_delay = 1;
4600
4601 /*
4602 * Sanitize sync polarity flags based on requested ones. If neither
4603 * positive or negative polarity is requested, treat this as meaning
4604 * negative polarity.
4605 */
4606 if (!(crtc_state->hw.adjusted_mode.flags &
4607 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
4608 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
4609
4610 if (!(crtc_state->hw.adjusted_mode.flags &
4611 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
4612 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
4613
4614 ret = compute_baseline_pipe_bpp(state, crtc);
4615 if (ret)
4616 return ret;
4617
4618 crtc_state->fec_enable = limits->force_fec_pipes & BIT(crtc->pipe);
4619 crtc_state->max_link_bpp_x16 = limits->max_bpp_x16[crtc->pipe];
4620
4621 if (crtc_state->pipe_bpp > fxp_q4_to_int(crtc_state->max_link_bpp_x16)) {
4622 drm_dbg_kms(display->drm,
4623 "[CRTC:%d:%s] Link bpp limited to " FXP_Q4_FMT "\n",
4624 crtc->base.base.id, crtc->base.name,
4625 FXP_Q4_ARGS(crtc_state->max_link_bpp_x16));
4626 crtc_state->bw_constrained = true;
4627 }
4628
4629 base_bpp = crtc_state->pipe_bpp;
4630
4631 /*
4632 * Determine the real pipe dimensions. Note that stereo modes can
4633 * increase the actual pipe size due to the frame doubling and
4634 * insertion of additional space for blanks between the frame. This
4635 * is stored in the crtc timings. We use the requested mode to do this
4636 * computation to clearly distinguish it from the adjusted mode, which
4637 * can be changed by the connectors in the below retry loop.
4638 */
4639 drm_mode_get_hv_timing(&crtc_state->hw.mode,
4640 &pipe_src_w, &pipe_src_h);
4641 drm_rect_init(&crtc_state->pipe_src, 0, 0,
4642 pipe_src_w, pipe_src_h);
4643
4644 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4645 struct intel_encoder *encoder =
4646 to_intel_encoder(connector_state->best_encoder);
4647
4648 if (connector_state->crtc != &crtc->base)
4649 continue;
4650
4651 if (!check_single_encoder_cloning(state, crtc, encoder)) {
4652 drm_dbg_kms(display->drm,
4653 "[ENCODER:%d:%s] rejecting invalid cloning configuration\n",
4654 encoder->base.base.id, encoder->base.name);
4655 return -EINVAL;
4656 }
4657
4658 /*
4659 * Determine output_types before calling the .compute_config()
4660 * hooks so that the hooks can use this information safely.
4661 */
4662 if (encoder->compute_output_type)
4663 crtc_state->output_types |=
4664 BIT(encoder->compute_output_type(encoder, crtc_state,
4665 connector_state));
4666 else
4667 crtc_state->output_types |= BIT(encoder->type);
4668 }
4669
4670 /* Ensure the port clock defaults are reset when retrying. */
4671 crtc_state->port_clock = 0;
4672 crtc_state->pixel_multiplier = 1;
4673
4674 /* Fill in default crtc timings, allow encoders to overwrite them. */
4675 drm_mode_set_crtcinfo(&crtc_state->hw.adjusted_mode,
4676 CRTC_STEREO_DOUBLE);
4677
4678 /* Pass our mode to the connectors and the CRTC to give them a chance to
4679 * adjust it according to limitations or connector properties, and also
4680 * a chance to reject the mode entirely.
4681 */
4682 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4683 struct intel_encoder *encoder =
4684 to_intel_encoder(connector_state->best_encoder);
4685
4686 if (connector_state->crtc != &crtc->base)
4687 continue;
4688
4689 ret = encoder->compute_config(encoder, crtc_state,
4690 connector_state);
4691 if (ret == -EDEADLK)
4692 return ret;
4693 if (ret < 0) {
4694 drm_dbg_kms(display->drm, "[ENCODER:%d:%s] config failure: %d\n",
4695 encoder->base.base.id, encoder->base.name, ret);
4696 return ret;
4697 }
4698 }
4699
4700 /* Set default port clock if not overwritten by the encoder. Needs to be
4701 * done afterwards in case the encoder adjusts the mode. */
4702 if (!crtc_state->port_clock)
4703 crtc_state->port_clock = crtc_state->hw.adjusted_mode.crtc_clock
4704 * crtc_state->pixel_multiplier;
4705
4706 ret = intel_crtc_compute_config(state, crtc);
4707 if (ret == -EDEADLK)
4708 return ret;
4709 if (ret < 0) {
4710 drm_dbg_kms(display->drm, "[CRTC:%d:%s] config failure: %d\n",
4711 crtc->base.base.id, crtc->base.name, ret);
4712 return ret;
4713 }
4714
4715 /* Dithering seems to not pass-through bits correctly when it should, so
4716 * only enable it on 6bpc panels and when its not a compliance
4717 * test requesting 6bpc video pattern.
4718 */
4719 crtc_state->dither = (crtc_state->pipe_bpp == 6*3) &&
4720 !crtc_state->dither_force_disable;
4721 drm_dbg_kms(display->drm,
4722 "[CRTC:%d:%s] hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
4723 crtc->base.base.id, crtc->base.name,
4724 base_bpp, crtc_state->pipe_bpp, crtc_state->dither);
4725
4726 return 0;
4727 }
4728
4729 static int
intel_modeset_pipe_config_late(struct intel_atomic_state * state,struct intel_crtc * crtc)4730 intel_modeset_pipe_config_late(struct intel_atomic_state *state,
4731 struct intel_crtc *crtc)
4732 {
4733 struct intel_crtc_state *crtc_state =
4734 intel_atomic_get_new_crtc_state(state, crtc);
4735 struct drm_connector_state *conn_state;
4736 struct drm_connector *connector;
4737 int i;
4738
4739 intel_vrr_compute_config_late(crtc_state);
4740
4741 for_each_new_connector_in_state(&state->base, connector,
4742 conn_state, i) {
4743 struct intel_encoder *encoder =
4744 to_intel_encoder(conn_state->best_encoder);
4745 int ret;
4746
4747 if (conn_state->crtc != &crtc->base ||
4748 !encoder->compute_config_late)
4749 continue;
4750
4751 ret = encoder->compute_config_late(encoder, crtc_state,
4752 conn_state);
4753 if (ret)
4754 return ret;
4755 }
4756
4757 return 0;
4758 }
4759
intel_fuzzy_clock_check(int clock1,int clock2)4760 bool intel_fuzzy_clock_check(int clock1, int clock2)
4761 {
4762 int diff;
4763
4764 if (clock1 == clock2)
4765 return true;
4766
4767 if (!clock1 || !clock2)
4768 return false;
4769
4770 diff = abs(clock1 - clock2);
4771
4772 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
4773 return true;
4774
4775 return false;
4776 }
4777
4778 static bool
intel_compare_link_m_n(const struct intel_link_m_n * m_n,const struct intel_link_m_n * m2_n2)4779 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
4780 const struct intel_link_m_n *m2_n2)
4781 {
4782 return m_n->tu == m2_n2->tu &&
4783 m_n->data_m == m2_n2->data_m &&
4784 m_n->data_n == m2_n2->data_n &&
4785 m_n->link_m == m2_n2->link_m &&
4786 m_n->link_n == m2_n2->link_n;
4787 }
4788
4789 static bool
intel_compare_infoframe(const union hdmi_infoframe * a,const union hdmi_infoframe * b)4790 intel_compare_infoframe(const union hdmi_infoframe *a,
4791 const union hdmi_infoframe *b)
4792 {
4793 return memcmp(a, b, sizeof(*a)) == 0;
4794 }
4795
4796 static bool
intel_compare_dp_vsc_sdp(const struct drm_dp_vsc_sdp * a,const struct drm_dp_vsc_sdp * b)4797 intel_compare_dp_vsc_sdp(const struct drm_dp_vsc_sdp *a,
4798 const struct drm_dp_vsc_sdp *b)
4799 {
4800 return a->pixelformat == b->pixelformat &&
4801 a->colorimetry == b->colorimetry &&
4802 a->bpc == b->bpc &&
4803 a->dynamic_range == b->dynamic_range &&
4804 a->content_type == b->content_type;
4805 }
4806
4807 static bool
intel_compare_dp_as_sdp(const struct drm_dp_as_sdp * a,const struct drm_dp_as_sdp * b)4808 intel_compare_dp_as_sdp(const struct drm_dp_as_sdp *a,
4809 const struct drm_dp_as_sdp *b)
4810 {
4811 return a->vtotal == b->vtotal &&
4812 a->target_rr == b->target_rr &&
4813 a->duration_incr_ms == b->duration_incr_ms &&
4814 a->duration_decr_ms == b->duration_decr_ms &&
4815 a->mode == b->mode;
4816 }
4817
4818 static bool
intel_compare_buffer(const u8 * a,const u8 * b,size_t len)4819 intel_compare_buffer(const u8 *a, const u8 *b, size_t len)
4820 {
4821 return memcmp(a, b, len) == 0;
4822 }
4823
4824 static void __printf(5, 6)
pipe_config_mismatch(struct drm_printer * p,bool fastset,const struct intel_crtc * crtc,const char * name,const char * format,...)4825 pipe_config_mismatch(struct drm_printer *p, bool fastset,
4826 const struct intel_crtc *crtc,
4827 const char *name, const char *format, ...)
4828 {
4829 struct va_format vaf;
4830 va_list args;
4831
4832 va_start(args, format);
4833 vaf.fmt = format;
4834 vaf.va = &args;
4835
4836 if (fastset)
4837 drm_printf(p, "[CRTC:%d:%s] fastset requirement not met in %s %pV\n",
4838 crtc->base.base.id, crtc->base.name, name, &vaf);
4839 else
4840 drm_printf(p, "[CRTC:%d:%s] mismatch in %s %pV\n",
4841 crtc->base.base.id, crtc->base.name, name, &vaf);
4842
4843 va_end(args);
4844 }
4845
4846 static void
pipe_config_infoframe_mismatch(struct drm_printer * p,bool fastset,const struct intel_crtc * crtc,const char * name,const union hdmi_infoframe * a,const union hdmi_infoframe * b)4847 pipe_config_infoframe_mismatch(struct drm_printer *p, bool fastset,
4848 const struct intel_crtc *crtc,
4849 const char *name,
4850 const union hdmi_infoframe *a,
4851 const union hdmi_infoframe *b)
4852 {
4853 struct intel_display *display = to_intel_display(crtc);
4854 const char *loglevel;
4855
4856 if (fastset) {
4857 if (!drm_debug_enabled(DRM_UT_KMS))
4858 return;
4859
4860 loglevel = KERN_DEBUG;
4861 } else {
4862 loglevel = KERN_ERR;
4863 }
4864
4865 pipe_config_mismatch(p, fastset, crtc, name, "infoframe");
4866
4867 drm_printf(p, "expected:\n");
4868 hdmi_infoframe_log(loglevel, display->drm->dev, a);
4869 drm_printf(p, "found:\n");
4870 hdmi_infoframe_log(loglevel, display->drm->dev, b);
4871 }
4872
4873 static void
pipe_config_dp_vsc_sdp_mismatch(struct drm_printer * p,bool fastset,const struct intel_crtc * crtc,const char * name,const struct drm_dp_vsc_sdp * a,const struct drm_dp_vsc_sdp * b)4874 pipe_config_dp_vsc_sdp_mismatch(struct drm_printer *p, bool fastset,
4875 const struct intel_crtc *crtc,
4876 const char *name,
4877 const struct drm_dp_vsc_sdp *a,
4878 const struct drm_dp_vsc_sdp *b)
4879 {
4880 pipe_config_mismatch(p, fastset, crtc, name, "dp vsc sdp");
4881
4882 drm_printf(p, "expected:\n");
4883 drm_dp_vsc_sdp_log(p, a);
4884 drm_printf(p, "found:\n");
4885 drm_dp_vsc_sdp_log(p, b);
4886 }
4887
4888 static void
pipe_config_dp_as_sdp_mismatch(struct drm_printer * p,bool fastset,const struct intel_crtc * crtc,const char * name,const struct drm_dp_as_sdp * a,const struct drm_dp_as_sdp * b)4889 pipe_config_dp_as_sdp_mismatch(struct drm_printer *p, bool fastset,
4890 const struct intel_crtc *crtc,
4891 const char *name,
4892 const struct drm_dp_as_sdp *a,
4893 const struct drm_dp_as_sdp *b)
4894 {
4895 pipe_config_mismatch(p, fastset, crtc, name, "dp as sdp");
4896
4897 drm_printf(p, "expected:\n");
4898 drm_dp_as_sdp_log(p, a);
4899 drm_printf(p, "found:\n");
4900 drm_dp_as_sdp_log(p, b);
4901 }
4902
4903 /* Returns the length up to and including the last differing byte */
4904 static size_t
memcmp_diff_len(const u8 * a,const u8 * b,size_t len)4905 memcmp_diff_len(const u8 *a, const u8 *b, size_t len)
4906 {
4907 int i;
4908
4909 for (i = len - 1; i >= 0; i--) {
4910 if (a[i] != b[i])
4911 return i + 1;
4912 }
4913
4914 return 0;
4915 }
4916
4917 static void
pipe_config_buffer_mismatch(struct drm_printer * p,bool fastset,const struct intel_crtc * crtc,const char * name,const u8 * a,const u8 * b,size_t len)4918 pipe_config_buffer_mismatch(struct drm_printer *p, bool fastset,
4919 const struct intel_crtc *crtc,
4920 const char *name,
4921 const u8 *a, const u8 *b, size_t len)
4922 {
4923 pipe_config_mismatch(p, fastset, crtc, name, "buffer");
4924
4925 /* only dump up to the last difference */
4926 len = memcmp_diff_len(a, b, len);
4927
4928 drm_print_hex_dump(p, "expected: ", a, len);
4929 drm_print_hex_dump(p, "found: ", b, len);
4930 }
4931
4932 static void
pipe_config_pll_mismatch(struct drm_printer * p,bool fastset,const struct intel_crtc * crtc,const char * name,const struct intel_dpll_hw_state * a,const struct intel_dpll_hw_state * b)4933 pipe_config_pll_mismatch(struct drm_printer *p, bool fastset,
4934 const struct intel_crtc *crtc,
4935 const char *name,
4936 const struct intel_dpll_hw_state *a,
4937 const struct intel_dpll_hw_state *b)
4938 {
4939 struct intel_display *display = to_intel_display(crtc);
4940
4941 pipe_config_mismatch(p, fastset, crtc, name, " "); /* stupid -Werror=format-zero-length */
4942
4943 drm_printf(p, "expected:\n");
4944 intel_dpll_dump_hw_state(display, p, a);
4945 drm_printf(p, "found:\n");
4946 intel_dpll_dump_hw_state(display, p, b);
4947 }
4948
4949 static void
pipe_config_cx0pll_mismatch(struct drm_printer * p,bool fastset,const struct intel_crtc * crtc,const char * name,const struct intel_cx0pll_state * a,const struct intel_cx0pll_state * b)4950 pipe_config_cx0pll_mismatch(struct drm_printer *p, bool fastset,
4951 const struct intel_crtc *crtc,
4952 const char *name,
4953 const struct intel_cx0pll_state *a,
4954 const struct intel_cx0pll_state *b)
4955 {
4956 struct intel_display *display = to_intel_display(crtc);
4957 char *chipname = a->use_c10 ? "C10" : "C20";
4958
4959 pipe_config_mismatch(p, fastset, crtc, name, chipname);
4960
4961 drm_printf(p, "expected:\n");
4962 intel_cx0pll_dump_hw_state(display, a);
4963 drm_printf(p, "found:\n");
4964 intel_cx0pll_dump_hw_state(display, b);
4965 }
4966
allow_vblank_delay_fastset(const struct intel_crtc_state * old_crtc_state)4967 static bool allow_vblank_delay_fastset(const struct intel_crtc_state *old_crtc_state)
4968 {
4969 struct intel_display *display = to_intel_display(old_crtc_state);
4970
4971 /*
4972 * Allow fastboot to fix up vblank delay (handled via LRR
4973 * codepaths), a bit dodgy as the registers aren't
4974 * double buffered but seems to be working more or less...
4975 */
4976 return HAS_LRR(display) && old_crtc_state->inherited &&
4977 !intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI);
4978 }
4979
4980 bool
intel_pipe_config_compare(const struct intel_crtc_state * current_config,const struct intel_crtc_state * pipe_config,bool fastset)4981 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
4982 const struct intel_crtc_state *pipe_config,
4983 bool fastset)
4984 {
4985 struct intel_display *display = to_intel_display(current_config);
4986 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
4987 struct drm_printer p;
4988 u32 exclude_infoframes = 0;
4989 bool ret = true;
4990
4991 if (fastset)
4992 p = drm_dbg_printer(display->drm, DRM_UT_KMS, NULL);
4993 else
4994 p = drm_err_printer(display->drm, NULL);
4995
4996 #define PIPE_CONF_CHECK_X(name) do { \
4997 if (current_config->name != pipe_config->name) { \
4998 BUILD_BUG_ON_MSG(__same_type(current_config->name, bool), \
4999 __stringify(name) " is bool"); \
5000 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \
5001 "(expected 0x%08x, found 0x%08x)", \
5002 current_config->name, \
5003 pipe_config->name); \
5004 ret = false; \
5005 } \
5006 } while (0)
5007
5008 #define PIPE_CONF_CHECK_X_WITH_MASK(name, mask) do { \
5009 if ((current_config->name & (mask)) != (pipe_config->name & (mask))) { \
5010 BUILD_BUG_ON_MSG(__same_type(current_config->name, bool), \
5011 __stringify(name) " is bool"); \
5012 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \
5013 "(expected 0x%08x, found 0x%08x)", \
5014 current_config->name & (mask), \
5015 pipe_config->name & (mask)); \
5016 ret = false; \
5017 } \
5018 } while (0)
5019
5020 #define PIPE_CONF_CHECK_I(name) do { \
5021 if (current_config->name != pipe_config->name) { \
5022 BUILD_BUG_ON_MSG(__same_type(current_config->name, bool), \
5023 __stringify(name) " is bool"); \
5024 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \
5025 "(expected %i, found %i)", \
5026 current_config->name, \
5027 pipe_config->name); \
5028 ret = false; \
5029 } \
5030 } while (0)
5031
5032 #define PIPE_CONF_CHECK_LLI(name) do { \
5033 if (current_config->name != pipe_config->name) { \
5034 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \
5035 "(expected %lli, found %lli)", \
5036 current_config->name, \
5037 pipe_config->name); \
5038 ret = false; \
5039 } \
5040 } while (0)
5041
5042 #define PIPE_CONF_CHECK_BOOL(name) do { \
5043 if (current_config->name != pipe_config->name) { \
5044 BUILD_BUG_ON_MSG(!__same_type(current_config->name, bool), \
5045 __stringify(name) " is not bool"); \
5046 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \
5047 "(expected %s, found %s)", \
5048 str_yes_no(current_config->name), \
5049 str_yes_no(pipe_config->name)); \
5050 ret = false; \
5051 } \
5052 } while (0)
5053
5054 #define PIPE_CONF_CHECK_P(name) do { \
5055 if (current_config->name != pipe_config->name) { \
5056 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \
5057 "(expected %p, found %p)", \
5058 current_config->name, \
5059 pipe_config->name); \
5060 ret = false; \
5061 } \
5062 } while (0)
5063
5064 #define PIPE_CONF_CHECK_M_N(name) do { \
5065 if (!intel_compare_link_m_n(¤t_config->name, \
5066 &pipe_config->name)) { \
5067 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \
5068 "(expected tu %i data %i/%i link %i/%i, " \
5069 "found tu %i, data %i/%i link %i/%i)", \
5070 current_config->name.tu, \
5071 current_config->name.data_m, \
5072 current_config->name.data_n, \
5073 current_config->name.link_m, \
5074 current_config->name.link_n, \
5075 pipe_config->name.tu, \
5076 pipe_config->name.data_m, \
5077 pipe_config->name.data_n, \
5078 pipe_config->name.link_m, \
5079 pipe_config->name.link_n); \
5080 ret = false; \
5081 } \
5082 } while (0)
5083
5084 #define PIPE_CONF_CHECK_PLL(name) do { \
5085 if (!intel_dpll_compare_hw_state(display, ¤t_config->name, \
5086 &pipe_config->name)) { \
5087 pipe_config_pll_mismatch(&p, fastset, crtc, __stringify(name), \
5088 ¤t_config->name, \
5089 &pipe_config->name); \
5090 ret = false; \
5091 } \
5092 } while (0)
5093
5094 #define PIPE_CONF_CHECK_PLL_CX0(name) do { \
5095 if (!intel_cx0pll_compare_hw_state(¤t_config->name, \
5096 &pipe_config->name)) { \
5097 pipe_config_cx0pll_mismatch(&p, fastset, crtc, __stringify(name), \
5098 ¤t_config->name, \
5099 &pipe_config->name); \
5100 ret = false; \
5101 } \
5102 } while (0)
5103
5104 #define PIPE_CONF_CHECK_TIMINGS(name) do { \
5105 PIPE_CONF_CHECK_I(name.crtc_hdisplay); \
5106 PIPE_CONF_CHECK_I(name.crtc_htotal); \
5107 PIPE_CONF_CHECK_I(name.crtc_hblank_start); \
5108 PIPE_CONF_CHECK_I(name.crtc_hblank_end); \
5109 PIPE_CONF_CHECK_I(name.crtc_hsync_start); \
5110 PIPE_CONF_CHECK_I(name.crtc_hsync_end); \
5111 PIPE_CONF_CHECK_I(name.crtc_vdisplay); \
5112 if (!fastset || !allow_vblank_delay_fastset(current_config)) \
5113 PIPE_CONF_CHECK_I(name.crtc_vblank_start); \
5114 PIPE_CONF_CHECK_I(name.crtc_vsync_start); \
5115 PIPE_CONF_CHECK_I(name.crtc_vsync_end); \
5116 if (!fastset || !pipe_config->update_lrr) { \
5117 PIPE_CONF_CHECK_I(name.crtc_vtotal); \
5118 PIPE_CONF_CHECK_I(name.crtc_vblank_end); \
5119 } \
5120 } while (0)
5121
5122 #define PIPE_CONF_CHECK_RECT(name) do { \
5123 PIPE_CONF_CHECK_I(name.x1); \
5124 PIPE_CONF_CHECK_I(name.x2); \
5125 PIPE_CONF_CHECK_I(name.y1); \
5126 PIPE_CONF_CHECK_I(name.y2); \
5127 } while (0)
5128
5129 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
5130 if ((current_config->name ^ pipe_config->name) & (mask)) { \
5131 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \
5132 "(%x) (expected %i, found %i)", \
5133 (mask), \
5134 current_config->name & (mask), \
5135 pipe_config->name & (mask)); \
5136 ret = false; \
5137 } \
5138 } while (0)
5139
5140 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
5141 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
5142 &pipe_config->infoframes.name)) { \
5143 pipe_config_infoframe_mismatch(&p, fastset, crtc, __stringify(name), \
5144 ¤t_config->infoframes.name, \
5145 &pipe_config->infoframes.name); \
5146 ret = false; \
5147 } \
5148 } while (0)
5149
5150 #define PIPE_CONF_CHECK_DP_VSC_SDP(name) do { \
5151 if (!intel_compare_dp_vsc_sdp(¤t_config->infoframes.name, \
5152 &pipe_config->infoframes.name)) { \
5153 pipe_config_dp_vsc_sdp_mismatch(&p, fastset, crtc, __stringify(name), \
5154 ¤t_config->infoframes.name, \
5155 &pipe_config->infoframes.name); \
5156 ret = false; \
5157 } \
5158 } while (0)
5159
5160 #define PIPE_CONF_CHECK_DP_AS_SDP(name) do { \
5161 if (!intel_compare_dp_as_sdp(¤t_config->infoframes.name, \
5162 &pipe_config->infoframes.name)) { \
5163 pipe_config_dp_as_sdp_mismatch(&p, fastset, crtc, __stringify(name), \
5164 ¤t_config->infoframes.name, \
5165 &pipe_config->infoframes.name); \
5166 ret = false; \
5167 } \
5168 } while (0)
5169
5170 #define PIPE_CONF_CHECK_BUFFER(name, len) do { \
5171 BUILD_BUG_ON(sizeof(current_config->name) != (len)); \
5172 BUILD_BUG_ON(sizeof(pipe_config->name) != (len)); \
5173 if (!intel_compare_buffer(current_config->name, pipe_config->name, (len))) { \
5174 pipe_config_buffer_mismatch(&p, fastset, crtc, __stringify(name), \
5175 current_config->name, \
5176 pipe_config->name, \
5177 (len)); \
5178 ret = false; \
5179 } \
5180 } while (0)
5181
5182 #define PIPE_CONF_CHECK_COLOR_LUT(lut, is_pre_csc_lut) do { \
5183 if (current_config->gamma_mode == pipe_config->gamma_mode && \
5184 !intel_color_lut_equal(current_config, \
5185 current_config->lut, pipe_config->lut, \
5186 is_pre_csc_lut)) { \
5187 pipe_config_mismatch(&p, fastset, crtc, __stringify(lut), \
5188 "hw_state doesn't match sw_state"); \
5189 ret = false; \
5190 } \
5191 } while (0)
5192
5193 #define PIPE_CONF_CHECK_CSC(name) do { \
5194 PIPE_CONF_CHECK_X(name.preoff[0]); \
5195 PIPE_CONF_CHECK_X(name.preoff[1]); \
5196 PIPE_CONF_CHECK_X(name.preoff[2]); \
5197 PIPE_CONF_CHECK_X(name.coeff[0]); \
5198 PIPE_CONF_CHECK_X(name.coeff[1]); \
5199 PIPE_CONF_CHECK_X(name.coeff[2]); \
5200 PIPE_CONF_CHECK_X(name.coeff[3]); \
5201 PIPE_CONF_CHECK_X(name.coeff[4]); \
5202 PIPE_CONF_CHECK_X(name.coeff[5]); \
5203 PIPE_CONF_CHECK_X(name.coeff[6]); \
5204 PIPE_CONF_CHECK_X(name.coeff[7]); \
5205 PIPE_CONF_CHECK_X(name.coeff[8]); \
5206 PIPE_CONF_CHECK_X(name.postoff[0]); \
5207 PIPE_CONF_CHECK_X(name.postoff[1]); \
5208 PIPE_CONF_CHECK_X(name.postoff[2]); \
5209 } while (0)
5210
5211 #define PIPE_CONF_QUIRK(quirk) \
5212 ((current_config->quirks | pipe_config->quirks) & (quirk))
5213
5214 PIPE_CONF_CHECK_BOOL(hw.enable);
5215 PIPE_CONF_CHECK_BOOL(hw.active);
5216
5217 PIPE_CONF_CHECK_I(cpu_transcoder);
5218 PIPE_CONF_CHECK_I(mst_master_transcoder);
5219
5220 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
5221 PIPE_CONF_CHECK_I(fdi_lanes);
5222 PIPE_CONF_CHECK_M_N(fdi_m_n);
5223
5224 PIPE_CONF_CHECK_I(lane_count);
5225 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
5226
5227 PIPE_CONF_CHECK_I(min_hblank);
5228
5229 if (HAS_DOUBLE_BUFFERED_M_N(display)) {
5230 if (!fastset || !pipe_config->update_m_n)
5231 PIPE_CONF_CHECK_M_N(dp_m_n);
5232 } else {
5233 PIPE_CONF_CHECK_M_N(dp_m_n);
5234 PIPE_CONF_CHECK_M_N(dp_m2_n2);
5235 }
5236
5237 PIPE_CONF_CHECK_X(output_types);
5238
5239 PIPE_CONF_CHECK_I(framestart_delay);
5240 PIPE_CONF_CHECK_I(msa_timing_delay);
5241
5242 PIPE_CONF_CHECK_TIMINGS(hw.pipe_mode);
5243 PIPE_CONF_CHECK_TIMINGS(hw.adjusted_mode);
5244
5245 PIPE_CONF_CHECK_I(pixel_multiplier);
5246
5247 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5248 DRM_MODE_FLAG_INTERLACE);
5249
5250 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
5251 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5252 DRM_MODE_FLAG_PHSYNC);
5253 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5254 DRM_MODE_FLAG_NHSYNC);
5255 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5256 DRM_MODE_FLAG_PVSYNC);
5257 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5258 DRM_MODE_FLAG_NVSYNC);
5259 }
5260
5261 PIPE_CONF_CHECK_I(output_format);
5262 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
5263 if ((DISPLAY_VER(display) < 8 && !display->platform.haswell) ||
5264 display->platform.valleyview || display->platform.cherryview)
5265 PIPE_CONF_CHECK_BOOL(limited_color_range);
5266
5267 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
5268 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
5269 PIPE_CONF_CHECK_BOOL(has_infoframe);
5270 PIPE_CONF_CHECK_BOOL(enhanced_framing);
5271 PIPE_CONF_CHECK_BOOL(fec_enable);
5272
5273 if (!fastset) {
5274 PIPE_CONF_CHECK_BOOL(has_audio);
5275 PIPE_CONF_CHECK_BUFFER(eld, MAX_ELD_BYTES);
5276 }
5277
5278 PIPE_CONF_CHECK_X(gmch_pfit.control);
5279 /* pfit ratios are autocomputed by the hw on gen4+ */
5280 if (DISPLAY_VER(display) < 4)
5281 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
5282 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
5283
5284 /*
5285 * Changing the EDP transcoder input mux
5286 * (A_ONOFF vs. A_ON) requires a full modeset.
5287 */
5288 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
5289
5290 if (!fastset) {
5291 PIPE_CONF_CHECK_RECT(pipe_src);
5292
5293 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
5294 PIPE_CONF_CHECK_RECT(pch_pfit.dst);
5295
5296 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
5297 PIPE_CONF_CHECK_I(pixel_rate);
5298
5299 PIPE_CONF_CHECK_X(gamma_mode);
5300 if (display->platform.cherryview)
5301 PIPE_CONF_CHECK_X(cgm_mode);
5302 else
5303 PIPE_CONF_CHECK_X(csc_mode);
5304 PIPE_CONF_CHECK_BOOL(gamma_enable);
5305 PIPE_CONF_CHECK_BOOL(csc_enable);
5306 PIPE_CONF_CHECK_BOOL(wgc_enable);
5307
5308 PIPE_CONF_CHECK_I(linetime);
5309 PIPE_CONF_CHECK_I(ips_linetime);
5310
5311 PIPE_CONF_CHECK_COLOR_LUT(pre_csc_lut, true);
5312 PIPE_CONF_CHECK_COLOR_LUT(post_csc_lut, false);
5313
5314 PIPE_CONF_CHECK_CSC(csc);
5315 PIPE_CONF_CHECK_CSC(output_csc);
5316 }
5317
5318 PIPE_CONF_CHECK_BOOL(double_wide);
5319
5320 if (display->dpll.mgr)
5321 PIPE_CONF_CHECK_P(shared_dpll);
5322
5323 /* FIXME convert everything over the dpll_mgr */
5324 if (display->dpll.mgr || HAS_GMCH(display))
5325 PIPE_CONF_CHECK_PLL(dpll_hw_state);
5326
5327 /* FIXME convert MTL+ platforms over to dpll_mgr */
5328 if (DISPLAY_VER(display) >= 14)
5329 PIPE_CONF_CHECK_PLL_CX0(dpll_hw_state.cx0pll);
5330
5331 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
5332 PIPE_CONF_CHECK_X(dsi_pll.div);
5333
5334 if (display->platform.g4x || DISPLAY_VER(display) >= 5)
5335 PIPE_CONF_CHECK_I(pipe_bpp);
5336
5337 if (!fastset || !pipe_config->update_m_n) {
5338 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_clock);
5339 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_clock);
5340 }
5341 PIPE_CONF_CHECK_I(port_clock);
5342
5343 PIPE_CONF_CHECK_I(min_voltage_level);
5344
5345 if (current_config->has_psr || pipe_config->has_psr)
5346 exclude_infoframes |= intel_hdmi_infoframe_enable(DP_SDP_VSC);
5347
5348 if (current_config->vrr.enable || pipe_config->vrr.enable)
5349 exclude_infoframes |= intel_hdmi_infoframe_enable(DP_SDP_ADAPTIVE_SYNC);
5350
5351 PIPE_CONF_CHECK_X_WITH_MASK(infoframes.enable, ~exclude_infoframes);
5352 PIPE_CONF_CHECK_X(infoframes.gcp);
5353 PIPE_CONF_CHECK_INFOFRAME(avi);
5354 PIPE_CONF_CHECK_INFOFRAME(spd);
5355 PIPE_CONF_CHECK_INFOFRAME(hdmi);
5356 if (!fastset) {
5357 PIPE_CONF_CHECK_INFOFRAME(drm);
5358 PIPE_CONF_CHECK_DP_AS_SDP(as_sdp);
5359 }
5360 PIPE_CONF_CHECK_DP_VSC_SDP(vsc);
5361
5362 PIPE_CONF_CHECK_X(sync_mode_slaves_mask);
5363 PIPE_CONF_CHECK_I(master_transcoder);
5364 PIPE_CONF_CHECK_X(joiner_pipes);
5365
5366 PIPE_CONF_CHECK_BOOL(dsc.config.block_pred_enable);
5367 PIPE_CONF_CHECK_BOOL(dsc.config.convert_rgb);
5368 PIPE_CONF_CHECK_BOOL(dsc.config.simple_422);
5369 PIPE_CONF_CHECK_BOOL(dsc.config.native_422);
5370 PIPE_CONF_CHECK_BOOL(dsc.config.native_420);
5371 PIPE_CONF_CHECK_BOOL(dsc.config.vbr_enable);
5372 PIPE_CONF_CHECK_I(dsc.config.line_buf_depth);
5373 PIPE_CONF_CHECK_I(dsc.config.bits_per_component);
5374 PIPE_CONF_CHECK_I(dsc.config.pic_width);
5375 PIPE_CONF_CHECK_I(dsc.config.pic_height);
5376 PIPE_CONF_CHECK_I(dsc.config.slice_width);
5377 PIPE_CONF_CHECK_I(dsc.config.slice_height);
5378 PIPE_CONF_CHECK_I(dsc.config.initial_dec_delay);
5379 PIPE_CONF_CHECK_I(dsc.config.initial_xmit_delay);
5380 PIPE_CONF_CHECK_I(dsc.config.scale_decrement_interval);
5381 PIPE_CONF_CHECK_I(dsc.config.scale_increment_interval);
5382 PIPE_CONF_CHECK_I(dsc.config.initial_scale_value);
5383 PIPE_CONF_CHECK_I(dsc.config.first_line_bpg_offset);
5384 PIPE_CONF_CHECK_I(dsc.config.flatness_min_qp);
5385 PIPE_CONF_CHECK_I(dsc.config.flatness_max_qp);
5386 PIPE_CONF_CHECK_I(dsc.config.slice_bpg_offset);
5387 PIPE_CONF_CHECK_I(dsc.config.nfl_bpg_offset);
5388 PIPE_CONF_CHECK_I(dsc.config.initial_offset);
5389 PIPE_CONF_CHECK_I(dsc.config.final_offset);
5390 PIPE_CONF_CHECK_I(dsc.config.rc_model_size);
5391 PIPE_CONF_CHECK_I(dsc.config.rc_quant_incr_limit0);
5392 PIPE_CONF_CHECK_I(dsc.config.rc_quant_incr_limit1);
5393 PIPE_CONF_CHECK_I(dsc.config.slice_chunk_size);
5394 PIPE_CONF_CHECK_I(dsc.config.second_line_bpg_offset);
5395 PIPE_CONF_CHECK_I(dsc.config.nsl_bpg_offset);
5396
5397 PIPE_CONF_CHECK_BOOL(dsc.compression_enable);
5398 PIPE_CONF_CHECK_I(dsc.num_streams);
5399 PIPE_CONF_CHECK_I(dsc.compressed_bpp_x16);
5400
5401 PIPE_CONF_CHECK_BOOL(splitter.enable);
5402 PIPE_CONF_CHECK_I(splitter.link_count);
5403 PIPE_CONF_CHECK_I(splitter.pixel_overlap);
5404
5405 if (!fastset) {
5406 PIPE_CONF_CHECK_BOOL(vrr.enable);
5407 PIPE_CONF_CHECK_I(vrr.vmin);
5408 PIPE_CONF_CHECK_I(vrr.vmax);
5409 PIPE_CONF_CHECK_I(vrr.flipline);
5410 PIPE_CONF_CHECK_I(vrr.vsync_start);
5411 PIPE_CONF_CHECK_I(vrr.vsync_end);
5412 PIPE_CONF_CHECK_LLI(cmrr.cmrr_m);
5413 PIPE_CONF_CHECK_LLI(cmrr.cmrr_n);
5414 PIPE_CONF_CHECK_BOOL(cmrr.enable);
5415 }
5416
5417 if (!fastset || intel_vrr_always_use_vrr_tg(display)) {
5418 PIPE_CONF_CHECK_I(vrr.pipeline_full);
5419 PIPE_CONF_CHECK_I(vrr.guardband);
5420 }
5421
5422 #undef PIPE_CONF_CHECK_X
5423 #undef PIPE_CONF_CHECK_I
5424 #undef PIPE_CONF_CHECK_LLI
5425 #undef PIPE_CONF_CHECK_BOOL
5426 #undef PIPE_CONF_CHECK_P
5427 #undef PIPE_CONF_CHECK_FLAGS
5428 #undef PIPE_CONF_CHECK_COLOR_LUT
5429 #undef PIPE_CONF_CHECK_TIMINGS
5430 #undef PIPE_CONF_CHECK_RECT
5431 #undef PIPE_CONF_QUIRK
5432
5433 return ret;
5434 }
5435
5436 static void
intel_verify_planes(struct intel_atomic_state * state)5437 intel_verify_planes(struct intel_atomic_state *state)
5438 {
5439 struct intel_plane *plane;
5440 const struct intel_plane_state *plane_state;
5441 int i;
5442
5443 for_each_new_intel_plane_in_state(state, plane,
5444 plane_state, i)
5445 assert_plane(plane, plane_state->is_y_plane ||
5446 plane_state->uapi.visible);
5447 }
5448
intel_modeset_pipe(struct intel_atomic_state * state,struct intel_crtc_state * crtc_state,const char * reason)5449 static int intel_modeset_pipe(struct intel_atomic_state *state,
5450 struct intel_crtc_state *crtc_state,
5451 const char *reason)
5452 {
5453 struct intel_display *display = to_intel_display(state);
5454 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5455 int ret;
5456
5457 drm_dbg_kms(display->drm, "[CRTC:%d:%s] Full modeset due to %s\n",
5458 crtc->base.base.id, crtc->base.name, reason);
5459
5460 ret = drm_atomic_add_affected_connectors(&state->base,
5461 &crtc->base);
5462 if (ret)
5463 return ret;
5464
5465 ret = intel_dp_tunnel_atomic_add_state_for_crtc(state, crtc);
5466 if (ret)
5467 return ret;
5468
5469 ret = intel_dp_mst_add_topology_state_for_crtc(state, crtc);
5470 if (ret)
5471 return ret;
5472
5473 ret = intel_atomic_add_affected_planes(state, crtc);
5474 if (ret)
5475 return ret;
5476
5477 crtc_state->uapi.mode_changed = true;
5478
5479 return 0;
5480 }
5481
5482 /**
5483 * intel_modeset_pipes_in_mask_early - force a full modeset on a set of pipes
5484 * @state: intel atomic state
5485 * @reason: the reason for the full modeset
5486 * @mask: mask of pipes to modeset
5487 *
5488 * Add pipes in @mask to @state and force a full modeset on the enabled ones
5489 * due to the description in @reason.
5490 * This function can be called only before new plane states are computed.
5491 *
5492 * Returns 0 in case of success, negative error code otherwise.
5493 */
intel_modeset_pipes_in_mask_early(struct intel_atomic_state * state,const char * reason,u8 mask)5494 int intel_modeset_pipes_in_mask_early(struct intel_atomic_state *state,
5495 const char *reason, u8 mask)
5496 {
5497 struct intel_display *display = to_intel_display(state);
5498 struct intel_crtc *crtc;
5499
5500 for_each_intel_crtc_in_pipe_mask(display->drm, crtc, mask) {
5501 struct intel_crtc_state *crtc_state;
5502 int ret;
5503
5504 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5505 if (IS_ERR(crtc_state))
5506 return PTR_ERR(crtc_state);
5507
5508 if (!crtc_state->hw.enable ||
5509 intel_crtc_needs_modeset(crtc_state))
5510 continue;
5511
5512 ret = intel_modeset_pipe(state, crtc_state, reason);
5513 if (ret)
5514 return ret;
5515 }
5516
5517 return 0;
5518 }
5519
5520 static void
intel_crtc_flag_modeset(struct intel_crtc_state * crtc_state)5521 intel_crtc_flag_modeset(struct intel_crtc_state *crtc_state)
5522 {
5523 crtc_state->uapi.mode_changed = true;
5524
5525 crtc_state->update_pipe = false;
5526 crtc_state->update_m_n = false;
5527 crtc_state->update_lrr = false;
5528 }
5529
5530 /**
5531 * intel_modeset_all_pipes_late - force a full modeset on all pipes
5532 * @state: intel atomic state
5533 * @reason: the reason for the full modeset
5534 *
5535 * Add all pipes to @state and force a full modeset on the active ones due to
5536 * the description in @reason.
5537 * This function can be called only after new plane states are computed already.
5538 *
5539 * Returns 0 in case of success, negative error code otherwise.
5540 */
intel_modeset_all_pipes_late(struct intel_atomic_state * state,const char * reason)5541 int intel_modeset_all_pipes_late(struct intel_atomic_state *state,
5542 const char *reason)
5543 {
5544 struct intel_display *display = to_intel_display(state);
5545 struct intel_crtc *crtc;
5546
5547 for_each_intel_crtc(display->drm, crtc) {
5548 struct intel_crtc_state *crtc_state;
5549 int ret;
5550
5551 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5552 if (IS_ERR(crtc_state))
5553 return PTR_ERR(crtc_state);
5554
5555 if (!crtc_state->hw.active ||
5556 intel_crtc_needs_modeset(crtc_state))
5557 continue;
5558
5559 ret = intel_modeset_pipe(state, crtc_state, reason);
5560 if (ret)
5561 return ret;
5562
5563 intel_crtc_flag_modeset(crtc_state);
5564
5565 crtc_state->update_planes |= crtc_state->active_planes;
5566 crtc_state->async_flip_planes = 0;
5567 crtc_state->do_async_flip = false;
5568 }
5569
5570 return 0;
5571 }
5572
intel_modeset_commit_pipes(struct intel_display * display,u8 pipe_mask,struct drm_modeset_acquire_ctx * ctx)5573 int intel_modeset_commit_pipes(struct intel_display *display,
5574 u8 pipe_mask,
5575 struct drm_modeset_acquire_ctx *ctx)
5576 {
5577 struct drm_atomic_state *state;
5578 struct intel_crtc *crtc;
5579 int ret;
5580
5581 state = drm_atomic_state_alloc(display->drm);
5582 if (!state)
5583 return -ENOMEM;
5584
5585 state->acquire_ctx = ctx;
5586 to_intel_atomic_state(state)->internal = true;
5587
5588 for_each_intel_crtc_in_pipe_mask(display->drm, crtc, pipe_mask) {
5589 struct intel_crtc_state *crtc_state =
5590 intel_atomic_get_crtc_state(state, crtc);
5591
5592 if (IS_ERR(crtc_state)) {
5593 ret = PTR_ERR(crtc_state);
5594 goto out;
5595 }
5596
5597 crtc_state->uapi.connectors_changed = true;
5598 }
5599
5600 ret = drm_atomic_commit(state);
5601 out:
5602 drm_atomic_state_put(state);
5603
5604 return ret;
5605 }
5606
5607 /*
5608 * This implements the workaround described in the "notes" section of the mode
5609 * set sequence documentation. When going from no pipes or single pipe to
5610 * multiple pipes, and planes are enabled after the pipe, we need to wait at
5611 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
5612 */
hsw_mode_set_planes_workaround(struct intel_atomic_state * state)5613 static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state)
5614 {
5615 struct intel_crtc_state *crtc_state;
5616 struct intel_crtc *crtc;
5617 struct intel_crtc_state *first_crtc_state = NULL;
5618 struct intel_crtc_state *other_crtc_state = NULL;
5619 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
5620 int i;
5621
5622 /* look at all crtc's that are going to be enabled in during modeset */
5623 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5624 if (!crtc_state->hw.active ||
5625 !intel_crtc_needs_modeset(crtc_state))
5626 continue;
5627
5628 if (first_crtc_state) {
5629 other_crtc_state = crtc_state;
5630 break;
5631 } else {
5632 first_crtc_state = crtc_state;
5633 first_pipe = crtc->pipe;
5634 }
5635 }
5636
5637 /* No workaround needed? */
5638 if (!first_crtc_state)
5639 return 0;
5640
5641 /* w/a possibly needed, check how many crtc's are already enabled. */
5642 for_each_intel_crtc(state->base.dev, crtc) {
5643 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5644 if (IS_ERR(crtc_state))
5645 return PTR_ERR(crtc_state);
5646
5647 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
5648
5649 if (!crtc_state->hw.active ||
5650 intel_crtc_needs_modeset(crtc_state))
5651 continue;
5652
5653 /* 2 or more enabled crtcs means no need for w/a */
5654 if (enabled_pipe != INVALID_PIPE)
5655 return 0;
5656
5657 enabled_pipe = crtc->pipe;
5658 }
5659
5660 if (enabled_pipe != INVALID_PIPE)
5661 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
5662 else if (other_crtc_state)
5663 other_crtc_state->hsw_workaround_pipe = first_pipe;
5664
5665 return 0;
5666 }
5667
intel_calc_active_pipes(struct intel_atomic_state * state,u8 active_pipes)5668 u8 intel_calc_active_pipes(struct intel_atomic_state *state,
5669 u8 active_pipes)
5670 {
5671 const struct intel_crtc_state *crtc_state;
5672 struct intel_crtc *crtc;
5673 int i;
5674
5675 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5676 if (crtc_state->hw.active)
5677 active_pipes |= BIT(crtc->pipe);
5678 else
5679 active_pipes &= ~BIT(crtc->pipe);
5680 }
5681
5682 return active_pipes;
5683 }
5684
intel_modeset_checks(struct intel_atomic_state * state)5685 static int intel_modeset_checks(struct intel_atomic_state *state)
5686 {
5687 struct intel_display *display = to_intel_display(state);
5688
5689 state->modeset = true;
5690
5691 if (display->platform.haswell)
5692 return hsw_mode_set_planes_workaround(state);
5693
5694 return 0;
5695 }
5696
lrr_params_changed(const struct drm_display_mode * old_adjusted_mode,const struct drm_display_mode * new_adjusted_mode)5697 static bool lrr_params_changed(const struct drm_display_mode *old_adjusted_mode,
5698 const struct drm_display_mode *new_adjusted_mode)
5699 {
5700 return old_adjusted_mode->crtc_vblank_start != new_adjusted_mode->crtc_vblank_start ||
5701 old_adjusted_mode->crtc_vblank_end != new_adjusted_mode->crtc_vblank_end ||
5702 old_adjusted_mode->crtc_vtotal != new_adjusted_mode->crtc_vtotal;
5703 }
5704
intel_crtc_check_fastset(const struct intel_crtc_state * old_crtc_state,struct intel_crtc_state * new_crtc_state)5705 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
5706 struct intel_crtc_state *new_crtc_state)
5707 {
5708 struct intel_display *display = to_intel_display(new_crtc_state);
5709 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
5710
5711 /* only allow LRR when the timings stay within the VRR range */
5712 if (old_crtc_state->vrr.in_range != new_crtc_state->vrr.in_range)
5713 new_crtc_state->update_lrr = false;
5714
5715 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true)) {
5716 drm_dbg_kms(display->drm, "[CRTC:%d:%s] fastset requirement not met, forcing full modeset\n",
5717 crtc->base.base.id, crtc->base.name);
5718 } else {
5719 if (allow_vblank_delay_fastset(old_crtc_state))
5720 new_crtc_state->update_lrr = true;
5721 new_crtc_state->uapi.mode_changed = false;
5722 }
5723
5724 if (intel_compare_link_m_n(&old_crtc_state->dp_m_n,
5725 &new_crtc_state->dp_m_n))
5726 new_crtc_state->update_m_n = false;
5727
5728 if (!lrr_params_changed(&old_crtc_state->hw.adjusted_mode,
5729 &new_crtc_state->hw.adjusted_mode))
5730 new_crtc_state->update_lrr = false;
5731
5732 if (intel_crtc_needs_modeset(new_crtc_state))
5733 intel_crtc_flag_modeset(new_crtc_state);
5734 else
5735 new_crtc_state->update_pipe = true;
5736 }
5737
intel_atomic_check_crtcs(struct intel_atomic_state * state)5738 static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
5739 {
5740 struct intel_display *display = to_intel_display(state);
5741 struct intel_crtc_state __maybe_unused *crtc_state;
5742 struct intel_crtc *crtc;
5743 int i;
5744
5745 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5746 int ret;
5747
5748 ret = intel_crtc_atomic_check(state, crtc);
5749 if (ret) {
5750 drm_dbg_atomic(display->drm,
5751 "[CRTC:%d:%s] atomic driver check failed\n",
5752 crtc->base.base.id, crtc->base.name);
5753 return ret;
5754 }
5755 }
5756
5757 return 0;
5758 }
5759
intel_cpu_transcoders_need_modeset(struct intel_atomic_state * state,u8 transcoders)5760 static bool intel_cpu_transcoders_need_modeset(struct intel_atomic_state *state,
5761 u8 transcoders)
5762 {
5763 const struct intel_crtc_state *new_crtc_state;
5764 struct intel_crtc *crtc;
5765 int i;
5766
5767 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
5768 if (new_crtc_state->hw.enable &&
5769 transcoders & BIT(new_crtc_state->cpu_transcoder) &&
5770 intel_crtc_needs_modeset(new_crtc_state))
5771 return true;
5772 }
5773
5774 return false;
5775 }
5776
intel_pipes_need_modeset(struct intel_atomic_state * state,u8 pipes)5777 static bool intel_pipes_need_modeset(struct intel_atomic_state *state,
5778 u8 pipes)
5779 {
5780 const struct intel_crtc_state *new_crtc_state;
5781 struct intel_crtc *crtc;
5782 int i;
5783
5784 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
5785 if (new_crtc_state->hw.enable &&
5786 pipes & BIT(crtc->pipe) &&
5787 intel_crtc_needs_modeset(new_crtc_state))
5788 return true;
5789 }
5790
5791 return false;
5792 }
5793
intel_atomic_check_joiner(struct intel_atomic_state * state,struct intel_crtc * primary_crtc)5794 static int intel_atomic_check_joiner(struct intel_atomic_state *state,
5795 struct intel_crtc *primary_crtc)
5796 {
5797 struct intel_display *display = to_intel_display(state);
5798 struct intel_crtc_state *primary_crtc_state =
5799 intel_atomic_get_new_crtc_state(state, primary_crtc);
5800 struct intel_crtc *secondary_crtc;
5801
5802 if (!primary_crtc_state->joiner_pipes)
5803 return 0;
5804
5805 /* sanity check */
5806 if (drm_WARN_ON(display->drm,
5807 primary_crtc->pipe != joiner_primary_pipe(primary_crtc_state)))
5808 return -EINVAL;
5809
5810 if (primary_crtc_state->joiner_pipes & ~joiner_pipes(display)) {
5811 drm_dbg_kms(display->drm,
5812 "[CRTC:%d:%s] Cannot act as joiner primary "
5813 "(need 0x%x as pipes, only 0x%x possible)\n",
5814 primary_crtc->base.base.id, primary_crtc->base.name,
5815 primary_crtc_state->joiner_pipes, joiner_pipes(display));
5816 return -EINVAL;
5817 }
5818
5819 for_each_intel_crtc_in_pipe_mask(display->drm, secondary_crtc,
5820 intel_crtc_joiner_secondary_pipes(primary_crtc_state)) {
5821 struct intel_crtc_state *secondary_crtc_state;
5822 int ret;
5823
5824 secondary_crtc_state = intel_atomic_get_crtc_state(&state->base, secondary_crtc);
5825 if (IS_ERR(secondary_crtc_state))
5826 return PTR_ERR(secondary_crtc_state);
5827
5828 /* primary being enabled, secondary was already configured? */
5829 if (secondary_crtc_state->uapi.enable) {
5830 drm_dbg_kms(display->drm,
5831 "[CRTC:%d:%s] secondary is enabled as normal CRTC, but "
5832 "[CRTC:%d:%s] claiming this CRTC for joiner.\n",
5833 secondary_crtc->base.base.id, secondary_crtc->base.name,
5834 primary_crtc->base.base.id, primary_crtc->base.name);
5835 return -EINVAL;
5836 }
5837
5838 /*
5839 * The state copy logic assumes the primary crtc gets processed
5840 * before the secondary crtc during the main compute_config loop.
5841 * This works because the crtcs are created in pipe order,
5842 * and the hardware requires primary pipe < secondary pipe as well.
5843 * Should that change we need to rethink the logic.
5844 */
5845 if (WARN_ON(drm_crtc_index(&primary_crtc->base) >
5846 drm_crtc_index(&secondary_crtc->base)))
5847 return -EINVAL;
5848
5849 drm_dbg_kms(display->drm,
5850 "[CRTC:%d:%s] Used as secondary for joiner primary [CRTC:%d:%s]\n",
5851 secondary_crtc->base.base.id, secondary_crtc->base.name,
5852 primary_crtc->base.base.id, primary_crtc->base.name);
5853
5854 secondary_crtc_state->joiner_pipes =
5855 primary_crtc_state->joiner_pipes;
5856
5857 ret = copy_joiner_crtc_state_modeset(state, secondary_crtc);
5858 if (ret)
5859 return ret;
5860 }
5861
5862 return 0;
5863 }
5864
kill_joiner_secondaries(struct intel_atomic_state * state,struct intel_crtc * primary_crtc)5865 static void kill_joiner_secondaries(struct intel_atomic_state *state,
5866 struct intel_crtc *primary_crtc)
5867 {
5868 struct intel_display *display = to_intel_display(state);
5869 struct intel_crtc_state *primary_crtc_state =
5870 intel_atomic_get_new_crtc_state(state, primary_crtc);
5871 struct intel_crtc *secondary_crtc;
5872
5873 for_each_intel_crtc_in_pipe_mask(display->drm, secondary_crtc,
5874 intel_crtc_joiner_secondary_pipes(primary_crtc_state)) {
5875 struct intel_crtc_state *secondary_crtc_state =
5876 intel_atomic_get_new_crtc_state(state, secondary_crtc);
5877
5878 secondary_crtc_state->joiner_pipes = 0;
5879
5880 intel_crtc_copy_uapi_to_hw_state_modeset(state, secondary_crtc);
5881 }
5882
5883 primary_crtc_state->joiner_pipes = 0;
5884 }
5885
5886 /**
5887 * DOC: asynchronous flip implementation
5888 *
5889 * Asynchronous page flip is the implementation for the DRM_MODE_PAGE_FLIP_ASYNC
5890 * flag. Currently async flip is only supported via the drmModePageFlip IOCTL.
5891 * Correspondingly, support is currently added for primary plane only.
5892 *
5893 * Async flip can only change the plane surface address, so anything else
5894 * changing is rejected from the intel_async_flip_check_hw() function.
5895 * Once this check is cleared, flip done interrupt is enabled using
5896 * the intel_crtc_enable_flip_done() function.
5897 *
5898 * As soon as the surface address register is written, flip done interrupt is
5899 * generated and the requested events are sent to the userspace in the interrupt
5900 * handler itself. The timestamp and sequence sent during the flip done event
5901 * correspond to the last vblank and have no relation to the actual time when
5902 * the flip done event was sent.
5903 */
intel_async_flip_check_uapi(struct intel_atomic_state * state,struct intel_crtc * crtc)5904 static int intel_async_flip_check_uapi(struct intel_atomic_state *state,
5905 struct intel_crtc *crtc)
5906 {
5907 struct intel_display *display = to_intel_display(state);
5908 const struct intel_crtc_state *new_crtc_state =
5909 intel_atomic_get_new_crtc_state(state, crtc);
5910 const struct intel_plane_state *old_plane_state;
5911 struct intel_plane_state *new_plane_state;
5912 struct intel_plane *plane;
5913 int i;
5914
5915 if (!new_crtc_state->uapi.async_flip)
5916 return 0;
5917
5918 if (!new_crtc_state->uapi.active) {
5919 drm_dbg_kms(display->drm,
5920 "[CRTC:%d:%s] not active\n",
5921 crtc->base.base.id, crtc->base.name);
5922 return -EINVAL;
5923 }
5924
5925 if (intel_crtc_needs_modeset(new_crtc_state)) {
5926 drm_dbg_kms(display->drm,
5927 "[CRTC:%d:%s] modeset required\n",
5928 crtc->base.base.id, crtc->base.name);
5929 return -EINVAL;
5930 }
5931
5932 /*
5933 * FIXME: joiner+async flip is busted currently.
5934 * Remove this check once the issues are fixed.
5935 */
5936 if (new_crtc_state->joiner_pipes) {
5937 drm_dbg_kms(display->drm,
5938 "[CRTC:%d:%s] async flip disallowed with joiner\n",
5939 crtc->base.base.id, crtc->base.name);
5940 return -EINVAL;
5941 }
5942
5943 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
5944 new_plane_state, i) {
5945 if (plane->pipe != crtc->pipe)
5946 continue;
5947
5948 /*
5949 * TODO: Async flip is only supported through the page flip IOCTL
5950 * as of now. So support currently added for primary plane only.
5951 * Support for other planes on platforms on which supports
5952 * this(vlv/chv and icl+) should be added when async flip is
5953 * enabled in the atomic IOCTL path.
5954 */
5955 if (!plane->async_flip) {
5956 drm_dbg_kms(display->drm,
5957 "[PLANE:%d:%s] async flip not supported\n",
5958 plane->base.base.id, plane->base.name);
5959 return -EINVAL;
5960 }
5961
5962 if (!old_plane_state->uapi.fb || !new_plane_state->uapi.fb) {
5963 drm_dbg_kms(display->drm,
5964 "[PLANE:%d:%s] no old or new framebuffer\n",
5965 plane->base.base.id, plane->base.name);
5966 return -EINVAL;
5967 }
5968 }
5969
5970 return 0;
5971 }
5972
intel_async_flip_check_hw(struct intel_atomic_state * state,struct intel_crtc * crtc)5973 static int intel_async_flip_check_hw(struct intel_atomic_state *state, struct intel_crtc *crtc)
5974 {
5975 struct intel_display *display = to_intel_display(state);
5976 const struct intel_crtc_state *old_crtc_state, *new_crtc_state;
5977 const struct intel_plane_state *new_plane_state, *old_plane_state;
5978 struct intel_plane *plane;
5979 int i;
5980
5981 old_crtc_state = intel_atomic_get_old_crtc_state(state, crtc);
5982 new_crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
5983
5984 if (!new_crtc_state->uapi.async_flip)
5985 return 0;
5986
5987 if (!new_crtc_state->hw.active) {
5988 drm_dbg_kms(display->drm,
5989 "[CRTC:%d:%s] not active\n",
5990 crtc->base.base.id, crtc->base.name);
5991 return -EINVAL;
5992 }
5993
5994 if (intel_crtc_needs_modeset(new_crtc_state)) {
5995 drm_dbg_kms(display->drm,
5996 "[CRTC:%d:%s] modeset required\n",
5997 crtc->base.base.id, crtc->base.name);
5998 return -EINVAL;
5999 }
6000
6001 if (old_crtc_state->active_planes != new_crtc_state->active_planes) {
6002 drm_dbg_kms(display->drm,
6003 "[CRTC:%d:%s] Active planes cannot be in async flip\n",
6004 crtc->base.base.id, crtc->base.name);
6005 return -EINVAL;
6006 }
6007
6008 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
6009 new_plane_state, i) {
6010 if (plane->pipe != crtc->pipe)
6011 continue;
6012
6013 /*
6014 * Only async flip capable planes should be in the state
6015 * if we're really about to ask the hardware to perform
6016 * an async flip. We should never get this far otherwise.
6017 */
6018 if (drm_WARN_ON(display->drm,
6019 new_crtc_state->do_async_flip && !plane->async_flip))
6020 return -EINVAL;
6021
6022 /*
6023 * Only check async flip capable planes other planes
6024 * may be involved in the initial commit due to
6025 * the wm0/ddb optimization.
6026 *
6027 * TODO maybe should track which planes actually
6028 * were requested to do the async flip...
6029 */
6030 if (!plane->async_flip)
6031 continue;
6032
6033 if (!intel_plane_can_async_flip(plane, new_plane_state->hw.fb->format->format,
6034 new_plane_state->hw.fb->modifier)) {
6035 drm_dbg_kms(display->drm,
6036 "[PLANE:%d:%s] pixel format %p4cc / modifier 0x%llx does not support async flip\n",
6037 plane->base.base.id, plane->base.name,
6038 &new_plane_state->hw.fb->format->format,
6039 new_plane_state->hw.fb->modifier);
6040 return -EINVAL;
6041 }
6042
6043 /*
6044 * We turn the first async flip request into a sync flip
6045 * so that we can reconfigure the plane (eg. change modifier).
6046 */
6047 if (!new_crtc_state->do_async_flip)
6048 continue;
6049
6050 if (old_plane_state->view.color_plane[0].mapping_stride !=
6051 new_plane_state->view.color_plane[0].mapping_stride) {
6052 drm_dbg_kms(display->drm,
6053 "[PLANE:%d:%s] Stride cannot be changed in async flip\n",
6054 plane->base.base.id, plane->base.name);
6055 return -EINVAL;
6056 }
6057
6058 if (old_plane_state->hw.fb->modifier !=
6059 new_plane_state->hw.fb->modifier) {
6060 drm_dbg_kms(display->drm,
6061 "[PLANE:%d:%s] Modifier cannot be changed in async flip\n",
6062 plane->base.base.id, plane->base.name);
6063 return -EINVAL;
6064 }
6065
6066 if (old_plane_state->hw.fb->format !=
6067 new_plane_state->hw.fb->format) {
6068 drm_dbg_kms(display->drm,
6069 "[PLANE:%d:%s] Pixel format cannot be changed in async flip\n",
6070 plane->base.base.id, plane->base.name);
6071 return -EINVAL;
6072 }
6073
6074 if (old_plane_state->hw.rotation !=
6075 new_plane_state->hw.rotation) {
6076 drm_dbg_kms(display->drm,
6077 "[PLANE:%d:%s] Rotation cannot be changed in async flip\n",
6078 plane->base.base.id, plane->base.name);
6079 return -EINVAL;
6080 }
6081
6082 if (skl_plane_aux_dist(old_plane_state, 0) !=
6083 skl_plane_aux_dist(new_plane_state, 0)) {
6084 drm_dbg_kms(display->drm,
6085 "[PLANE:%d:%s] AUX_DIST cannot be changed in async flip\n",
6086 plane->base.base.id, plane->base.name);
6087 return -EINVAL;
6088 }
6089
6090 if (!drm_rect_equals(&old_plane_state->uapi.src, &new_plane_state->uapi.src) ||
6091 !drm_rect_equals(&old_plane_state->uapi.dst, &new_plane_state->uapi.dst)) {
6092 drm_dbg_kms(display->drm,
6093 "[PLANE:%d:%s] Size/co-ordinates cannot be changed in async flip\n",
6094 plane->base.base.id, plane->base.name);
6095 return -EINVAL;
6096 }
6097
6098 if (old_plane_state->hw.alpha != new_plane_state->hw.alpha) {
6099 drm_dbg_kms(display->drm,
6100 "[PLANES:%d:%s] Alpha value cannot be changed in async flip\n",
6101 plane->base.base.id, plane->base.name);
6102 return -EINVAL;
6103 }
6104
6105 if (old_plane_state->hw.pixel_blend_mode !=
6106 new_plane_state->hw.pixel_blend_mode) {
6107 drm_dbg_kms(display->drm,
6108 "[PLANE:%d:%s] Pixel blend mode cannot be changed in async flip\n",
6109 plane->base.base.id, plane->base.name);
6110 return -EINVAL;
6111 }
6112
6113 if (old_plane_state->hw.color_encoding != new_plane_state->hw.color_encoding) {
6114 drm_dbg_kms(display->drm,
6115 "[PLANE:%d:%s] Color encoding cannot be changed in async flip\n",
6116 plane->base.base.id, plane->base.name);
6117 return -EINVAL;
6118 }
6119
6120 if (old_plane_state->hw.color_range != new_plane_state->hw.color_range) {
6121 drm_dbg_kms(display->drm,
6122 "[PLANE:%d:%s] Color range cannot be changed in async flip\n",
6123 plane->base.base.id, plane->base.name);
6124 return -EINVAL;
6125 }
6126
6127 /* plane decryption is allow to change only in synchronous flips */
6128 if (old_plane_state->decrypt != new_plane_state->decrypt) {
6129 drm_dbg_kms(display->drm,
6130 "[PLANE:%d:%s] Decryption cannot be changed in async flip\n",
6131 plane->base.base.id, plane->base.name);
6132 return -EINVAL;
6133 }
6134 }
6135
6136 return 0;
6137 }
6138
intel_joiner_add_affected_crtcs(struct intel_atomic_state * state)6139 static int intel_joiner_add_affected_crtcs(struct intel_atomic_state *state)
6140 {
6141 struct intel_display *display = to_intel_display(state);
6142 const struct intel_plane_state *plane_state;
6143 struct intel_crtc_state *crtc_state;
6144 struct intel_plane *plane;
6145 struct intel_crtc *crtc;
6146 u8 affected_pipes = 0;
6147 u8 modeset_pipes = 0;
6148 int i;
6149
6150 /*
6151 * Any plane which is in use by the joiner needs its crtc.
6152 * Pull those in first as this will not have happened yet
6153 * if the plane remains disabled according to uapi.
6154 */
6155 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
6156 crtc = to_intel_crtc(plane_state->hw.crtc);
6157 if (!crtc)
6158 continue;
6159
6160 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
6161 if (IS_ERR(crtc_state))
6162 return PTR_ERR(crtc_state);
6163 }
6164
6165 /* Now pull in all joined crtcs */
6166 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6167 affected_pipes |= crtc_state->joiner_pipes;
6168 if (intel_crtc_needs_modeset(crtc_state))
6169 modeset_pipes |= crtc_state->joiner_pipes;
6170 }
6171
6172 for_each_intel_crtc_in_pipe_mask(display->drm, crtc, affected_pipes) {
6173 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
6174 if (IS_ERR(crtc_state))
6175 return PTR_ERR(crtc_state);
6176 }
6177
6178 for_each_intel_crtc_in_pipe_mask(display->drm, crtc, modeset_pipes) {
6179 int ret;
6180
6181 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
6182
6183 crtc_state->uapi.mode_changed = true;
6184
6185 ret = drm_atomic_add_affected_connectors(&state->base, &crtc->base);
6186 if (ret)
6187 return ret;
6188
6189 ret = intel_atomic_add_affected_planes(state, crtc);
6190 if (ret)
6191 return ret;
6192 }
6193
6194 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6195 /* Kill old joiner link, we may re-establish afterwards */
6196 if (intel_crtc_needs_modeset(crtc_state) &&
6197 intel_crtc_is_joiner_primary(crtc_state))
6198 kill_joiner_secondaries(state, crtc);
6199 }
6200
6201 return 0;
6202 }
6203
intel_atomic_check_config(struct intel_atomic_state * state,struct intel_link_bw_limits * limits,enum pipe * failed_pipe)6204 static int intel_atomic_check_config(struct intel_atomic_state *state,
6205 struct intel_link_bw_limits *limits,
6206 enum pipe *failed_pipe)
6207 {
6208 struct intel_display *display = to_intel_display(state);
6209 struct intel_crtc_state *new_crtc_state;
6210 struct intel_crtc *crtc;
6211 int ret;
6212 int i;
6213
6214 *failed_pipe = INVALID_PIPE;
6215
6216 ret = intel_joiner_add_affected_crtcs(state);
6217 if (ret)
6218 return ret;
6219
6220 ret = intel_fdi_add_affected_crtcs(state);
6221 if (ret)
6222 return ret;
6223
6224 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6225 if (!intel_crtc_needs_modeset(new_crtc_state)) {
6226 if (intel_crtc_is_joiner_secondary(new_crtc_state))
6227 copy_joiner_crtc_state_nomodeset(state, crtc);
6228 else
6229 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc);
6230 continue;
6231 }
6232
6233 if (drm_WARN_ON(display->drm, intel_crtc_is_joiner_secondary(new_crtc_state)))
6234 continue;
6235
6236 ret = intel_crtc_prepare_cleared_state(state, crtc);
6237 if (ret)
6238 goto fail;
6239
6240 if (!new_crtc_state->hw.enable)
6241 continue;
6242
6243 ret = intel_modeset_pipe_config(state, crtc, limits);
6244 if (ret)
6245 goto fail;
6246 }
6247
6248 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6249 if (!intel_crtc_needs_modeset(new_crtc_state))
6250 continue;
6251
6252 if (drm_WARN_ON(display->drm, intel_crtc_is_joiner_secondary(new_crtc_state)))
6253 continue;
6254
6255 if (!new_crtc_state->hw.enable)
6256 continue;
6257
6258 ret = intel_modeset_pipe_config_late(state, crtc);
6259 if (ret)
6260 goto fail;
6261 }
6262
6263 fail:
6264 if (ret)
6265 *failed_pipe = crtc->pipe;
6266
6267 return ret;
6268 }
6269
intel_atomic_check_config_and_link(struct intel_atomic_state * state)6270 static int intel_atomic_check_config_and_link(struct intel_atomic_state *state)
6271 {
6272 struct intel_link_bw_limits new_limits;
6273 struct intel_link_bw_limits old_limits;
6274 int ret;
6275
6276 intel_link_bw_init_limits(state, &new_limits);
6277 old_limits = new_limits;
6278
6279 while (true) {
6280 enum pipe failed_pipe;
6281
6282 ret = intel_atomic_check_config(state, &new_limits,
6283 &failed_pipe);
6284 if (ret) {
6285 /*
6286 * The bpp limit for a pipe is below the minimum it supports, set the
6287 * limit to the minimum and recalculate the config.
6288 */
6289 if (ret == -EINVAL &&
6290 intel_link_bw_set_bpp_limit_for_pipe(state,
6291 &old_limits,
6292 &new_limits,
6293 failed_pipe))
6294 continue;
6295
6296 break;
6297 }
6298
6299 old_limits = new_limits;
6300
6301 ret = intel_link_bw_atomic_check(state, &new_limits);
6302 if (ret != -EAGAIN)
6303 break;
6304 }
6305
6306 return ret;
6307 }
6308 /**
6309 * intel_atomic_check - validate state object
6310 * @dev: drm device
6311 * @_state: state to validate
6312 */
intel_atomic_check(struct drm_device * dev,struct drm_atomic_state * _state)6313 int intel_atomic_check(struct drm_device *dev,
6314 struct drm_atomic_state *_state)
6315 {
6316 struct intel_display *display = to_intel_display(dev);
6317 struct intel_atomic_state *state = to_intel_atomic_state(_state);
6318 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6319 struct intel_crtc *crtc;
6320 int ret, i;
6321 bool any_ms = false;
6322
6323 if (!intel_display_driver_check_access(display))
6324 return -ENODEV;
6325
6326 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6327 new_crtc_state, i) {
6328 /*
6329 * crtc's state no longer considered to be inherited
6330 * after the first userspace/client initiated commit.
6331 */
6332 if (!state->internal)
6333 new_crtc_state->inherited = false;
6334
6335 if (new_crtc_state->inherited != old_crtc_state->inherited)
6336 new_crtc_state->uapi.mode_changed = true;
6337
6338 if (new_crtc_state->uapi.scaling_filter !=
6339 old_crtc_state->uapi.scaling_filter)
6340 new_crtc_state->uapi.mode_changed = true;
6341 }
6342
6343 intel_vrr_check_modeset(state);
6344
6345 ret = drm_atomic_helper_check_modeset(dev, &state->base);
6346 if (ret)
6347 goto fail;
6348
6349 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6350 ret = intel_async_flip_check_uapi(state, crtc);
6351 if (ret)
6352 return ret;
6353 }
6354
6355 ret = intel_atomic_check_config_and_link(state);
6356 if (ret)
6357 goto fail;
6358
6359 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6360 if (!intel_crtc_needs_modeset(new_crtc_state))
6361 continue;
6362
6363 if (intel_crtc_is_joiner_secondary(new_crtc_state)) {
6364 drm_WARN_ON(display->drm, new_crtc_state->uapi.enable);
6365 continue;
6366 }
6367
6368 ret = intel_atomic_check_joiner(state, crtc);
6369 if (ret)
6370 goto fail;
6371 }
6372
6373 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6374 new_crtc_state, i) {
6375 if (!intel_crtc_needs_modeset(new_crtc_state))
6376 continue;
6377
6378 intel_joiner_adjust_pipe_src(new_crtc_state);
6379
6380 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
6381 }
6382
6383 /**
6384 * Check if fastset is allowed by external dependencies like other
6385 * pipes and transcoders.
6386 *
6387 * Right now it only forces a fullmodeset when the MST master
6388 * transcoder did not changed but the pipe of the master transcoder
6389 * needs a fullmodeset so all slaves also needs to do a fullmodeset or
6390 * in case of port synced crtcs, if one of the synced crtcs
6391 * needs a full modeset, all other synced crtcs should be
6392 * forced a full modeset.
6393 */
6394 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6395 if (!new_crtc_state->hw.enable || intel_crtc_needs_modeset(new_crtc_state))
6396 continue;
6397
6398 if (intel_dp_mst_crtc_needs_modeset(state, crtc))
6399 intel_crtc_flag_modeset(new_crtc_state);
6400
6401 if (intel_dp_mst_is_slave_trans(new_crtc_state)) {
6402 enum transcoder master = new_crtc_state->mst_master_transcoder;
6403
6404 if (intel_cpu_transcoders_need_modeset(state, BIT(master)))
6405 intel_crtc_flag_modeset(new_crtc_state);
6406 }
6407
6408 if (is_trans_port_sync_mode(new_crtc_state)) {
6409 u8 trans = new_crtc_state->sync_mode_slaves_mask;
6410
6411 if (new_crtc_state->master_transcoder != INVALID_TRANSCODER)
6412 trans |= BIT(new_crtc_state->master_transcoder);
6413
6414 if (intel_cpu_transcoders_need_modeset(state, trans))
6415 intel_crtc_flag_modeset(new_crtc_state);
6416 }
6417
6418 if (new_crtc_state->joiner_pipes) {
6419 if (intel_pipes_need_modeset(state, new_crtc_state->joiner_pipes))
6420 intel_crtc_flag_modeset(new_crtc_state);
6421 }
6422 }
6423
6424 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6425 new_crtc_state, i) {
6426 if (!intel_crtc_needs_modeset(new_crtc_state))
6427 continue;
6428
6429 any_ms = true;
6430
6431 intel_release_shared_dplls(state, crtc);
6432 }
6433
6434 if (any_ms && !check_digital_port_conflicts(state)) {
6435 drm_dbg_kms(display->drm,
6436 "rejecting conflicting digital port configuration\n");
6437 ret = -EINVAL;
6438 goto fail;
6439 }
6440
6441 ret = intel_atomic_check_planes(state);
6442 if (ret)
6443 goto fail;
6444
6445 ret = intel_compute_global_watermarks(state);
6446 if (ret)
6447 goto fail;
6448
6449 ret = intel_bw_atomic_check(state, any_ms);
6450 if (ret)
6451 goto fail;
6452
6453 ret = intel_cdclk_atomic_check(state, &any_ms);
6454 if (ret)
6455 goto fail;
6456
6457 if (intel_any_crtc_needs_modeset(state))
6458 any_ms = true;
6459
6460 if (any_ms) {
6461 ret = intel_modeset_checks(state);
6462 if (ret)
6463 goto fail;
6464
6465 ret = intel_modeset_calc_cdclk(state);
6466 if (ret)
6467 return ret;
6468 }
6469
6470 ret = intel_pmdemand_atomic_check(state);
6471 if (ret)
6472 goto fail;
6473
6474 ret = intel_atomic_check_crtcs(state);
6475 if (ret)
6476 goto fail;
6477
6478 ret = intel_fbc_atomic_check(state);
6479 if (ret)
6480 goto fail;
6481
6482 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6483 new_crtc_state, i) {
6484 intel_color_assert_luts(new_crtc_state);
6485
6486 ret = intel_async_flip_check_hw(state, crtc);
6487 if (ret)
6488 goto fail;
6489
6490 /* Either full modeset or fastset (or neither), never both */
6491 drm_WARN_ON(display->drm,
6492 intel_crtc_needs_modeset(new_crtc_state) &&
6493 intel_crtc_needs_fastset(new_crtc_state));
6494
6495 if (!intel_crtc_needs_modeset(new_crtc_state) &&
6496 !intel_crtc_needs_fastset(new_crtc_state))
6497 continue;
6498
6499 intel_crtc_state_dump(new_crtc_state, state,
6500 intel_crtc_needs_modeset(new_crtc_state) ?
6501 "modeset" : "fastset");
6502 }
6503
6504 return 0;
6505
6506 fail:
6507 if (ret == -EDEADLK)
6508 return ret;
6509
6510 /*
6511 * FIXME would probably be nice to know which crtc specifically
6512 * caused the failure, in cases where we can pinpoint it.
6513 */
6514 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6515 new_crtc_state, i)
6516 intel_crtc_state_dump(new_crtc_state, state, "failed");
6517
6518 return ret;
6519 }
6520
intel_atomic_prepare_commit(struct intel_atomic_state * state)6521 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
6522 {
6523 int ret;
6524
6525 ret = drm_atomic_helper_prepare_planes(state->base.dev, &state->base);
6526 if (ret < 0)
6527 return ret;
6528
6529 return 0;
6530 }
6531
intel_crtc_arm_fifo_underrun(struct intel_crtc * crtc,struct intel_crtc_state * crtc_state)6532 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
6533 struct intel_crtc_state *crtc_state)
6534 {
6535 struct intel_display *display = to_intel_display(crtc);
6536
6537 if (DISPLAY_VER(display) != 2 || crtc_state->active_planes)
6538 intel_set_cpu_fifo_underrun_reporting(display, crtc->pipe, true);
6539
6540 if (crtc_state->has_pch_encoder) {
6541 enum pipe pch_transcoder =
6542 intel_crtc_pch_transcoder(crtc);
6543
6544 intel_set_pch_fifo_underrun_reporting(display, pch_transcoder, true);
6545 }
6546 }
6547
intel_pipe_fastset(const struct intel_crtc_state * old_crtc_state,const struct intel_crtc_state * new_crtc_state)6548 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
6549 const struct intel_crtc_state *new_crtc_state)
6550 {
6551 struct intel_display *display = to_intel_display(new_crtc_state);
6552 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6553
6554 /*
6555 * Update pipe size and adjust fitter if needed: the reason for this is
6556 * that in compute_mode_changes we check the native mode (not the pfit
6557 * mode) to see if we can flip rather than do a full mode set. In the
6558 * fastboot case, we'll flip, but if we don't update the pipesrc and
6559 * pfit state, we'll end up with a big fb scanned out into the wrong
6560 * sized surface.
6561 */
6562 intel_set_pipe_src_size(new_crtc_state);
6563
6564 /* on skylake this is done by detaching scalers */
6565 if (DISPLAY_VER(display) >= 9) {
6566 if (new_crtc_state->pch_pfit.enabled)
6567 skl_pfit_enable(new_crtc_state);
6568 } else if (HAS_PCH_SPLIT(display)) {
6569 if (new_crtc_state->pch_pfit.enabled)
6570 ilk_pfit_enable(new_crtc_state);
6571 else if (old_crtc_state->pch_pfit.enabled)
6572 ilk_pfit_disable(old_crtc_state);
6573 }
6574
6575 /*
6576 * The register is supposedly single buffered so perhaps
6577 * not 100% correct to do this here. But SKL+ calculate
6578 * this based on the adjust pixel rate so pfit changes do
6579 * affect it and so it must be updated for fastsets.
6580 * HSW/BDW only really need this here for fastboot, after
6581 * that the value should not change without a full modeset.
6582 */
6583 if (DISPLAY_VER(display) >= 9 ||
6584 display->platform.broadwell || display->platform.haswell)
6585 hsw_set_linetime_wm(new_crtc_state);
6586
6587 if (new_crtc_state->update_m_n)
6588 intel_cpu_transcoder_set_m1_n1(crtc, new_crtc_state->cpu_transcoder,
6589 &new_crtc_state->dp_m_n);
6590
6591 if (new_crtc_state->update_lrr)
6592 intel_set_transcoder_timings_lrr(new_crtc_state);
6593 }
6594
commit_pipe_pre_planes(struct intel_atomic_state * state,struct intel_crtc * crtc)6595 static void commit_pipe_pre_planes(struct intel_atomic_state *state,
6596 struct intel_crtc *crtc)
6597 {
6598 struct intel_display *display = to_intel_display(state);
6599 const struct intel_crtc_state *old_crtc_state =
6600 intel_atomic_get_old_crtc_state(state, crtc);
6601 const struct intel_crtc_state *new_crtc_state =
6602 intel_atomic_get_new_crtc_state(state, crtc);
6603 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
6604
6605 drm_WARN_ON(display->drm, new_crtc_state->use_dsb);
6606
6607 /*
6608 * During modesets pipe configuration was programmed as the
6609 * CRTC was enabled.
6610 */
6611 if (!modeset) {
6612 if (intel_crtc_needs_color_update(new_crtc_state))
6613 intel_color_commit_arm(NULL, new_crtc_state);
6614
6615 if (DISPLAY_VER(display) >= 9 || display->platform.broadwell)
6616 bdw_set_pipe_misc(NULL, new_crtc_state);
6617
6618 if (intel_crtc_needs_fastset(new_crtc_state))
6619 intel_pipe_fastset(old_crtc_state, new_crtc_state);
6620 }
6621
6622 intel_psr2_program_trans_man_trk_ctl(NULL, new_crtc_state);
6623
6624 intel_atomic_update_watermarks(state, crtc);
6625 }
6626
commit_pipe_post_planes(struct intel_atomic_state * state,struct intel_crtc * crtc)6627 static void commit_pipe_post_planes(struct intel_atomic_state *state,
6628 struct intel_crtc *crtc)
6629 {
6630 struct intel_display *display = to_intel_display(state);
6631 const struct intel_crtc_state *new_crtc_state =
6632 intel_atomic_get_new_crtc_state(state, crtc);
6633
6634 drm_WARN_ON(display->drm, new_crtc_state->use_dsb);
6635
6636 /*
6637 * Disable the scaler(s) after the plane(s) so that we don't
6638 * get a catastrophic underrun even if the two operations
6639 * end up happening in two different frames.
6640 */
6641 if (DISPLAY_VER(display) >= 9 &&
6642 !intel_crtc_needs_modeset(new_crtc_state))
6643 skl_detach_scalers(NULL, new_crtc_state);
6644
6645 if (intel_crtc_vrr_enabling(state, crtc))
6646 intel_vrr_enable(new_crtc_state);
6647 }
6648
intel_enable_crtc(struct intel_atomic_state * state,struct intel_crtc * crtc)6649 static void intel_enable_crtc(struct intel_atomic_state *state,
6650 struct intel_crtc *crtc)
6651 {
6652 struct intel_display *display = to_intel_display(state);
6653 const struct intel_crtc_state *new_crtc_state =
6654 intel_atomic_get_new_crtc_state(state, crtc);
6655 struct intel_crtc *pipe_crtc;
6656
6657 if (!intel_crtc_needs_modeset(new_crtc_state))
6658 return;
6659
6660 for_each_intel_crtc_in_pipe_mask_reverse(display->drm, pipe_crtc,
6661 intel_crtc_joined_pipe_mask(new_crtc_state)) {
6662 const struct intel_crtc_state *pipe_crtc_state =
6663 intel_atomic_get_new_crtc_state(state, pipe_crtc);
6664
6665 /* VRR will be enable later, if required */
6666 intel_crtc_update_active_timings(pipe_crtc_state, false);
6667 }
6668
6669 intel_psr_notify_pipe_change(state, crtc, true);
6670
6671 display->funcs.display->crtc_enable(state, crtc);
6672
6673 /* vblanks work again, re-enable pipe CRC. */
6674 intel_crtc_enable_pipe_crc(crtc);
6675 }
6676
intel_pre_update_crtc(struct intel_atomic_state * state,struct intel_crtc * crtc)6677 static void intel_pre_update_crtc(struct intel_atomic_state *state,
6678 struct intel_crtc *crtc)
6679 {
6680 struct intel_display *display = to_intel_display(state);
6681 const struct intel_crtc_state *old_crtc_state =
6682 intel_atomic_get_old_crtc_state(state, crtc);
6683 struct intel_crtc_state *new_crtc_state =
6684 intel_atomic_get_new_crtc_state(state, crtc);
6685 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
6686
6687 if (old_crtc_state->inherited ||
6688 intel_crtc_needs_modeset(new_crtc_state)) {
6689 if (HAS_DPT(display))
6690 intel_dpt_configure(crtc);
6691 }
6692
6693 if (!modeset) {
6694 if (new_crtc_state->preload_luts &&
6695 intel_crtc_needs_color_update(new_crtc_state))
6696 intel_color_load_luts(new_crtc_state);
6697
6698 intel_pre_plane_update(state, crtc);
6699
6700 if (intel_crtc_needs_fastset(new_crtc_state))
6701 intel_encoders_update_pipe(state, crtc);
6702
6703 if (DISPLAY_VER(display) >= 11 &&
6704 intel_crtc_needs_fastset(new_crtc_state))
6705 icl_set_pipe_chicken(new_crtc_state);
6706
6707 if (vrr_params_changed(old_crtc_state, new_crtc_state) ||
6708 cmrr_params_changed(old_crtc_state, new_crtc_state))
6709 intel_vrr_set_transcoder_timings(new_crtc_state);
6710 }
6711
6712 intel_fbc_update(state, crtc);
6713
6714 drm_WARN_ON(display->drm, !intel_display_power_is_enabled(display, POWER_DOMAIN_DC_OFF));
6715
6716 if (!modeset &&
6717 intel_crtc_needs_color_update(new_crtc_state) &&
6718 !new_crtc_state->use_dsb)
6719 intel_color_commit_noarm(NULL, new_crtc_state);
6720
6721 if (!new_crtc_state->use_dsb)
6722 intel_crtc_planes_update_noarm(NULL, state, crtc);
6723 }
6724
intel_update_crtc(struct intel_atomic_state * state,struct intel_crtc * crtc)6725 static void intel_update_crtc(struct intel_atomic_state *state,
6726 struct intel_crtc *crtc)
6727 {
6728 const struct intel_crtc_state *old_crtc_state =
6729 intel_atomic_get_old_crtc_state(state, crtc);
6730 struct intel_crtc_state *new_crtc_state =
6731 intel_atomic_get_new_crtc_state(state, crtc);
6732
6733 if (new_crtc_state->use_dsb) {
6734 intel_crtc_prepare_vblank_event(new_crtc_state, &crtc->dsb_event);
6735
6736 intel_dsb_commit(new_crtc_state->dsb_commit, false);
6737 } else {
6738 /* Perform vblank evasion around commit operation */
6739 intel_pipe_update_start(state, crtc);
6740
6741 if (new_crtc_state->dsb_commit)
6742 intel_dsb_commit(new_crtc_state->dsb_commit, false);
6743
6744 commit_pipe_pre_planes(state, crtc);
6745
6746 intel_crtc_planes_update_arm(NULL, state, crtc);
6747
6748 commit_pipe_post_planes(state, crtc);
6749
6750 intel_pipe_update_end(state, crtc);
6751 }
6752
6753 /*
6754 * VRR/Seamless M/N update may need to update frame timings.
6755 *
6756 * FIXME Should be synchronized with the start of vblank somehow...
6757 */
6758 if (intel_crtc_vrr_enabling(state, crtc) ||
6759 new_crtc_state->update_m_n || new_crtc_state->update_lrr)
6760 intel_crtc_update_active_timings(new_crtc_state,
6761 new_crtc_state->vrr.enable);
6762
6763 /*
6764 * We usually enable FIFO underrun interrupts as part of the
6765 * CRTC enable sequence during modesets. But when we inherit a
6766 * valid pipe configuration from the BIOS we need to take care
6767 * of enabling them on the CRTC's first fastset.
6768 */
6769 if (intel_crtc_needs_fastset(new_crtc_state) &&
6770 old_crtc_state->inherited)
6771 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
6772 }
6773
intel_old_crtc_state_disables(struct intel_atomic_state * state,struct intel_crtc * crtc)6774 static void intel_old_crtc_state_disables(struct intel_atomic_state *state,
6775 struct intel_crtc *crtc)
6776 {
6777 struct intel_display *display = to_intel_display(state);
6778 const struct intel_crtc_state *old_crtc_state =
6779 intel_atomic_get_old_crtc_state(state, crtc);
6780 struct intel_crtc *pipe_crtc;
6781
6782 /*
6783 * We need to disable pipe CRC before disabling the pipe,
6784 * or we race against vblank off.
6785 */
6786 for_each_intel_crtc_in_pipe_mask(display->drm, pipe_crtc,
6787 intel_crtc_joined_pipe_mask(old_crtc_state))
6788 intel_crtc_disable_pipe_crc(pipe_crtc);
6789
6790 intel_psr_notify_pipe_change(state, crtc, false);
6791
6792 display->funcs.display->crtc_disable(state, crtc);
6793
6794 for_each_intel_crtc_in_pipe_mask(display->drm, pipe_crtc,
6795 intel_crtc_joined_pipe_mask(old_crtc_state)) {
6796 const struct intel_crtc_state *new_pipe_crtc_state =
6797 intel_atomic_get_new_crtc_state(state, pipe_crtc);
6798
6799 pipe_crtc->active = false;
6800 intel_fbc_disable(pipe_crtc);
6801
6802 if (!new_pipe_crtc_state->hw.active)
6803 intel_initial_watermarks(state, pipe_crtc);
6804 }
6805 }
6806
intel_commit_modeset_disables(struct intel_atomic_state * state)6807 static void intel_commit_modeset_disables(struct intel_atomic_state *state)
6808 {
6809 struct intel_display *display = to_intel_display(state);
6810 const struct intel_crtc_state *new_crtc_state, *old_crtc_state;
6811 struct intel_crtc *crtc;
6812 u8 disable_pipes = 0;
6813 int i;
6814
6815 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6816 new_crtc_state, i) {
6817 if (!intel_crtc_needs_modeset(new_crtc_state))
6818 continue;
6819
6820 /*
6821 * Needs to be done even for pipes
6822 * that weren't enabled previously.
6823 */
6824 intel_pre_plane_update(state, crtc);
6825
6826 if (!old_crtc_state->hw.active)
6827 continue;
6828
6829 disable_pipes |= BIT(crtc->pipe);
6830 }
6831
6832 for_each_old_intel_crtc_in_state(state, crtc, old_crtc_state, i) {
6833 if ((disable_pipes & BIT(crtc->pipe)) == 0)
6834 continue;
6835
6836 intel_crtc_disable_planes(state, crtc);
6837
6838 drm_vblank_work_flush_all(&crtc->base);
6839 }
6840
6841 /* Only disable port sync and MST slaves */
6842 for_each_old_intel_crtc_in_state(state, crtc, old_crtc_state, i) {
6843 if ((disable_pipes & BIT(crtc->pipe)) == 0)
6844 continue;
6845
6846 if (intel_crtc_is_joiner_secondary(old_crtc_state))
6847 continue;
6848
6849 /* In case of Transcoder port Sync master slave CRTCs can be
6850 * assigned in any order and we need to make sure that
6851 * slave CRTCs are disabled first and then master CRTC since
6852 * Slave vblanks are masked till Master Vblanks.
6853 */
6854 if (!is_trans_port_sync_slave(old_crtc_state) &&
6855 !intel_dp_mst_is_slave_trans(old_crtc_state))
6856 continue;
6857
6858 intel_old_crtc_state_disables(state, crtc);
6859
6860 disable_pipes &= ~intel_crtc_joined_pipe_mask(old_crtc_state);
6861 }
6862
6863 /* Disable everything else left on */
6864 for_each_old_intel_crtc_in_state(state, crtc, old_crtc_state, i) {
6865 if ((disable_pipes & BIT(crtc->pipe)) == 0)
6866 continue;
6867
6868 if (intel_crtc_is_joiner_secondary(old_crtc_state))
6869 continue;
6870
6871 intel_old_crtc_state_disables(state, crtc);
6872
6873 disable_pipes &= ~intel_crtc_joined_pipe_mask(old_crtc_state);
6874 }
6875
6876 drm_WARN_ON(display->drm, disable_pipes);
6877 }
6878
intel_commit_modeset_enables(struct intel_atomic_state * state)6879 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
6880 {
6881 struct intel_crtc_state *new_crtc_state;
6882 struct intel_crtc *crtc;
6883 int i;
6884
6885 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6886 if (!new_crtc_state->hw.active)
6887 continue;
6888
6889 intel_enable_crtc(state, crtc);
6890 intel_pre_update_crtc(state, crtc);
6891 }
6892
6893 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6894 if (!new_crtc_state->hw.active)
6895 continue;
6896
6897 intel_update_crtc(state, crtc);
6898 }
6899 }
6900
skl_commit_modeset_enables(struct intel_atomic_state * state)6901 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
6902 {
6903 struct intel_display *display = to_intel_display(state);
6904 struct intel_crtc *crtc;
6905 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6906 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
6907 u8 update_pipes = 0, modeset_pipes = 0;
6908 int i;
6909
6910 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
6911 enum pipe pipe = crtc->pipe;
6912
6913 if (!new_crtc_state->hw.active)
6914 continue;
6915
6916 /* ignore allocations for crtc's that have been turned off. */
6917 if (!intel_crtc_needs_modeset(new_crtc_state)) {
6918 entries[pipe] = old_crtc_state->wm.skl.ddb;
6919 update_pipes |= BIT(pipe);
6920 } else {
6921 modeset_pipes |= BIT(pipe);
6922 }
6923 }
6924
6925 /*
6926 * Whenever the number of active pipes changes, we need to make sure we
6927 * update the pipes in the right order so that their ddb allocations
6928 * never overlap with each other between CRTC updates. Otherwise we'll
6929 * cause pipe underruns and other bad stuff.
6930 *
6931 * So first lets enable all pipes that do not need a fullmodeset as
6932 * those don't have any external dependency.
6933 */
6934 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6935 enum pipe pipe = crtc->pipe;
6936
6937 if ((update_pipes & BIT(pipe)) == 0)
6938 continue;
6939
6940 intel_pre_update_crtc(state, crtc);
6941 }
6942
6943 intel_dbuf_mbus_pre_ddb_update(state);
6944
6945 while (update_pipes) {
6946 /*
6947 * Commit in reverse order to make joiner primary
6948 * send the uapi events after secondaries are done.
6949 */
6950 for_each_oldnew_intel_crtc_in_state_reverse(state, crtc, old_crtc_state,
6951 new_crtc_state, i) {
6952 enum pipe pipe = crtc->pipe;
6953
6954 if ((update_pipes & BIT(pipe)) == 0)
6955 continue;
6956
6957 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
6958 entries, I915_MAX_PIPES, pipe))
6959 continue;
6960
6961 entries[pipe] = new_crtc_state->wm.skl.ddb;
6962 update_pipes &= ~BIT(pipe);
6963
6964 intel_update_crtc(state, crtc);
6965
6966 /*
6967 * If this is an already active pipe, it's DDB changed,
6968 * and this isn't the last pipe that needs updating
6969 * then we need to wait for a vblank to pass for the
6970 * new ddb allocation to take effect.
6971 */
6972 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
6973 &old_crtc_state->wm.skl.ddb) &&
6974 (update_pipes | modeset_pipes))
6975 intel_crtc_wait_for_next_vblank(crtc);
6976 }
6977 }
6978
6979 intel_dbuf_mbus_post_ddb_update(state);
6980
6981 update_pipes = modeset_pipes;
6982
6983 /*
6984 * Enable all pipes that needs a modeset and do not depends on other
6985 * pipes
6986 */
6987 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6988 enum pipe pipe = crtc->pipe;
6989
6990 if ((modeset_pipes & BIT(pipe)) == 0)
6991 continue;
6992
6993 if (intel_crtc_is_joiner_secondary(new_crtc_state))
6994 continue;
6995
6996 if (intel_dp_mst_is_slave_trans(new_crtc_state) ||
6997 is_trans_port_sync_master(new_crtc_state))
6998 continue;
6999
7000 modeset_pipes &= ~intel_crtc_joined_pipe_mask(new_crtc_state);
7001
7002 intel_enable_crtc(state, crtc);
7003 }
7004
7005 /*
7006 * Then we enable all remaining pipes that depend on other
7007 * pipes: MST slaves and port sync masters
7008 */
7009 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7010 enum pipe pipe = crtc->pipe;
7011
7012 if ((modeset_pipes & BIT(pipe)) == 0)
7013 continue;
7014
7015 if (intel_crtc_is_joiner_secondary(new_crtc_state))
7016 continue;
7017
7018 modeset_pipes &= ~intel_crtc_joined_pipe_mask(new_crtc_state);
7019
7020 intel_enable_crtc(state, crtc);
7021 }
7022
7023 /*
7024 * Finally we do the plane updates/etc. for all pipes that got enabled.
7025 */
7026 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7027 enum pipe pipe = crtc->pipe;
7028
7029 if ((update_pipes & BIT(pipe)) == 0)
7030 continue;
7031
7032 intel_pre_update_crtc(state, crtc);
7033 }
7034
7035 /*
7036 * Commit in reverse order to make joiner primary
7037 * send the uapi events after secondaries are done.
7038 */
7039 for_each_new_intel_crtc_in_state_reverse(state, crtc, new_crtc_state, i) {
7040 enum pipe pipe = crtc->pipe;
7041
7042 if ((update_pipes & BIT(pipe)) == 0)
7043 continue;
7044
7045 drm_WARN_ON(display->drm,
7046 skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
7047 entries, I915_MAX_PIPES, pipe));
7048
7049 entries[pipe] = new_crtc_state->wm.skl.ddb;
7050 update_pipes &= ~BIT(pipe);
7051
7052 intel_update_crtc(state, crtc);
7053 }
7054
7055 drm_WARN_ON(display->drm, modeset_pipes);
7056 drm_WARN_ON(display->drm, update_pipes);
7057 }
7058
intel_atomic_commit_fence_wait(struct intel_atomic_state * intel_state)7059 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
7060 {
7061 struct drm_i915_private *i915 = to_i915(intel_state->base.dev);
7062 struct drm_plane *plane;
7063 struct drm_plane_state *new_plane_state;
7064 int ret, i;
7065
7066 for_each_new_plane_in_state(&intel_state->base, plane, new_plane_state, i) {
7067 if (new_plane_state->fence) {
7068 ret = dma_fence_wait_timeout(new_plane_state->fence, false,
7069 i915_fence_timeout(i915));
7070 if (ret <= 0)
7071 break;
7072
7073 dma_fence_put(new_plane_state->fence);
7074 new_plane_state->fence = NULL;
7075 }
7076 }
7077 }
7078
intel_atomic_dsb_wait_commit(struct intel_crtc_state * crtc_state)7079 static void intel_atomic_dsb_wait_commit(struct intel_crtc_state *crtc_state)
7080 {
7081 if (crtc_state->dsb_commit)
7082 intel_dsb_wait(crtc_state->dsb_commit);
7083
7084 intel_color_wait_commit(crtc_state);
7085 }
7086
intel_atomic_dsb_cleanup(struct intel_crtc_state * crtc_state)7087 static void intel_atomic_dsb_cleanup(struct intel_crtc_state *crtc_state)
7088 {
7089 if (crtc_state->dsb_commit) {
7090 intel_dsb_cleanup(crtc_state->dsb_commit);
7091 crtc_state->dsb_commit = NULL;
7092 }
7093
7094 intel_color_cleanup_commit(crtc_state);
7095 }
7096
intel_atomic_cleanup_work(struct work_struct * work)7097 static void intel_atomic_cleanup_work(struct work_struct *work)
7098 {
7099 struct intel_atomic_state *state =
7100 container_of(work, struct intel_atomic_state, cleanup_work);
7101 struct intel_display *display = to_intel_display(state);
7102 struct intel_crtc_state *old_crtc_state;
7103 struct intel_crtc *crtc;
7104 int i;
7105
7106 for_each_old_intel_crtc_in_state(state, crtc, old_crtc_state, i)
7107 intel_atomic_dsb_cleanup(old_crtc_state);
7108
7109 drm_atomic_helper_cleanup_planes(display->drm, &state->base);
7110 drm_atomic_helper_commit_cleanup_done(&state->base);
7111 drm_atomic_state_put(&state->base);
7112 }
7113
intel_atomic_prepare_plane_clear_colors(struct intel_atomic_state * state)7114 static void intel_atomic_prepare_plane_clear_colors(struct intel_atomic_state *state)
7115 {
7116 struct intel_display *display = to_intel_display(state);
7117 struct intel_plane *plane;
7118 struct intel_plane_state *plane_state;
7119 int i;
7120
7121 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
7122 struct drm_framebuffer *fb = plane_state->hw.fb;
7123 int cc_plane;
7124 int ret;
7125
7126 if (!fb)
7127 continue;
7128
7129 cc_plane = intel_fb_rc_ccs_cc_plane(fb);
7130 if (cc_plane < 0)
7131 continue;
7132
7133 /*
7134 * The layout of the fast clear color value expected by HW
7135 * (the DRM ABI requiring this value to be located in fb at
7136 * offset 0 of cc plane, plane #2 previous generations or
7137 * plane #1 for flat ccs):
7138 * - 4 x 4 bytes per-channel value
7139 * (in surface type specific float/int format provided by the fb user)
7140 * - 8 bytes native color value used by the display
7141 * (converted/written by GPU during a fast clear operation using the
7142 * above per-channel values)
7143 *
7144 * The commit's FB prepare hook already ensured that FB obj is pinned and the
7145 * caller made sure that the object is synced wrt. the related color clear value
7146 * GPU write on it.
7147 */
7148 ret = intel_bo_read_from_page(intel_fb_bo(fb),
7149 fb->offsets[cc_plane] + 16,
7150 &plane_state->ccval,
7151 sizeof(plane_state->ccval));
7152 /* The above could only fail if the FB obj has an unexpected backing store type. */
7153 drm_WARN_ON(display->drm, ret);
7154 }
7155 }
7156
intel_atomic_dsb_prepare(struct intel_atomic_state * state,struct intel_crtc * crtc)7157 static void intel_atomic_dsb_prepare(struct intel_atomic_state *state,
7158 struct intel_crtc *crtc)
7159 {
7160 struct intel_display *display = to_intel_display(state);
7161 struct intel_crtc_state *new_crtc_state =
7162 intel_atomic_get_new_crtc_state(state, crtc);
7163
7164 if (!new_crtc_state->hw.active)
7165 return;
7166
7167 if (state->base.legacy_cursor_update)
7168 return;
7169
7170 /* FIXME deal with everything */
7171 new_crtc_state->use_dsb =
7172 !new_crtc_state->do_async_flip &&
7173 (DISPLAY_VER(display) >= 20 || !new_crtc_state->has_psr) &&
7174 !intel_crtc_needs_modeset(new_crtc_state) &&
7175 !intel_crtc_needs_fastset(new_crtc_state);
7176
7177 intel_color_prepare_commit(state, crtc);
7178 }
7179
intel_atomic_dsb_finish(struct intel_atomic_state * state,struct intel_crtc * crtc)7180 static void intel_atomic_dsb_finish(struct intel_atomic_state *state,
7181 struct intel_crtc *crtc)
7182 {
7183 struct intel_display *display = to_intel_display(state);
7184 struct intel_crtc_state *new_crtc_state =
7185 intel_atomic_get_new_crtc_state(state, crtc);
7186
7187 if (!new_crtc_state->use_dsb && !new_crtc_state->dsb_color_vblank)
7188 return;
7189
7190 /*
7191 * Rough estimate:
7192 * ~64 registers per each plane * 8 planes = 512
7193 * Double that for pipe stuff and other overhead.
7194 */
7195 new_crtc_state->dsb_commit = intel_dsb_prepare(state, crtc, INTEL_DSB_0,
7196 new_crtc_state->use_dsb ? 1024 : 16);
7197 if (!new_crtc_state->dsb_commit) {
7198 new_crtc_state->use_dsb = false;
7199 intel_color_cleanup_commit(new_crtc_state);
7200 return;
7201 }
7202
7203 if (new_crtc_state->use_dsb) {
7204 if (intel_crtc_needs_color_update(new_crtc_state))
7205 intel_color_commit_noarm(new_crtc_state->dsb_commit,
7206 new_crtc_state);
7207 intel_crtc_planes_update_noarm(new_crtc_state->dsb_commit,
7208 state, crtc);
7209
7210 /*
7211 * Ensure we have "Frame Change" event when PSR state is
7212 * SRDENT(PSR1) or DEEP_SLEEP(PSR2). Otherwise DSB vblank
7213 * evasion hangs as PIPEDSL is reading as 0.
7214 */
7215 intel_psr_trigger_frame_change_event(new_crtc_state->dsb_commit,
7216 state, crtc);
7217
7218 intel_dsb_vblank_evade(state, new_crtc_state->dsb_commit);
7219
7220 if (intel_crtc_needs_color_update(new_crtc_state))
7221 intel_color_commit_arm(new_crtc_state->dsb_commit,
7222 new_crtc_state);
7223 bdw_set_pipe_misc(new_crtc_state->dsb_commit,
7224 new_crtc_state);
7225 intel_psr2_program_trans_man_trk_ctl(new_crtc_state->dsb_commit,
7226 new_crtc_state);
7227 intel_crtc_planes_update_arm(new_crtc_state->dsb_commit,
7228 state, crtc);
7229
7230 if (DISPLAY_VER(display) >= 9)
7231 skl_detach_scalers(new_crtc_state->dsb_commit,
7232 new_crtc_state);
7233
7234 if (!new_crtc_state->dsb_color_vblank) {
7235 intel_dsb_wait_vblanks(new_crtc_state->dsb_commit, 1);
7236
7237 intel_vrr_send_push(new_crtc_state->dsb_commit, new_crtc_state);
7238 intel_dsb_wait_vblank_delay(state, new_crtc_state->dsb_commit);
7239 intel_vrr_check_push_sent(new_crtc_state->dsb_commit, new_crtc_state);
7240 intel_dsb_interrupt(new_crtc_state->dsb_commit);
7241 }
7242 }
7243
7244 if (new_crtc_state->dsb_color_vblank)
7245 intel_dsb_chain(state, new_crtc_state->dsb_commit,
7246 new_crtc_state->dsb_color_vblank, true);
7247
7248 intel_dsb_finish(new_crtc_state->dsb_commit);
7249 }
7250
intel_atomic_commit_tail(struct intel_atomic_state * state)7251 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
7252 {
7253 struct intel_display *display = to_intel_display(state);
7254 struct drm_i915_private __maybe_unused *dev_priv = to_i915(display->drm);
7255 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
7256 struct intel_crtc *crtc;
7257 struct intel_power_domain_mask put_domains[I915_MAX_PIPES] = {};
7258 intel_wakeref_t wakeref = NULL;
7259 int i;
7260
7261 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7262 intel_atomic_dsb_prepare(state, crtc);
7263
7264 intel_atomic_commit_fence_wait(state);
7265
7266 intel_td_flush(display);
7267
7268 intel_atomic_prepare_plane_clear_colors(state);
7269
7270 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7271 intel_fbc_prepare_dirty_rect(state, crtc);
7272
7273 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7274 intel_atomic_dsb_finish(state, crtc);
7275
7276 drm_atomic_helper_wait_for_dependencies(&state->base);
7277 drm_dp_mst_atomic_wait_for_dependencies(&state->base);
7278 intel_atomic_global_state_wait_for_dependencies(state);
7279
7280 /*
7281 * During full modesets we write a lot of registers, wait
7282 * for PLLs, etc. Doing that while DC states are enabled
7283 * is not a good idea.
7284 *
7285 * During fastsets and other updates we also need to
7286 * disable DC states due to the following scenario:
7287 * 1. DC5 exit and PSR exit happen
7288 * 2. Some or all _noarm() registers are written
7289 * 3. Due to some long delay PSR is re-entered
7290 * 4. DC5 entry -> DMC saves the already written new
7291 * _noarm() registers and the old not yet written
7292 * _arm() registers
7293 * 5. DC5 exit -> DMC restores a mixture of old and
7294 * new register values and arms the update
7295 * 6. PSR exit -> hardware latches a mixture of old and
7296 * new register values -> corrupted frame, or worse
7297 * 7. New _arm() registers are finally written
7298 * 8. Hardware finally latches a complete set of new
7299 * register values, and subsequent frames will be OK again
7300 *
7301 * Also note that due to the pipe CSC hardware issues on
7302 * SKL/GLK DC states must remain off until the pipe CSC
7303 * state readout has happened. Otherwise we risk corrupting
7304 * the CSC latched register values with the readout (see
7305 * skl_read_csc() and skl_color_commit_noarm()).
7306 */
7307 wakeref = intel_display_power_get(display, POWER_DOMAIN_DC_OFF);
7308
7309 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7310 new_crtc_state, i) {
7311 if (intel_crtc_needs_modeset(new_crtc_state) ||
7312 intel_crtc_needs_fastset(new_crtc_state))
7313 intel_modeset_get_crtc_power_domains(new_crtc_state, &put_domains[crtc->pipe]);
7314 }
7315
7316 intel_commit_modeset_disables(state);
7317
7318 intel_dp_tunnel_atomic_alloc_bw(state);
7319
7320 /* FIXME: Eventually get rid of our crtc->config pointer */
7321 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7322 crtc->config = new_crtc_state;
7323
7324 /*
7325 * In XE_LPD+ Pmdemand combines many parameters such as voltage index,
7326 * plls, cdclk frequency, QGV point selection parameter etc. Voltage
7327 * index, cdclk/ddiclk frequencies are supposed to be configured before
7328 * the cdclk config is set.
7329 */
7330 intel_pmdemand_pre_plane_update(state);
7331
7332 if (state->modeset) {
7333 drm_atomic_helper_update_legacy_modeset_state(display->drm, &state->base);
7334
7335 intel_set_cdclk_pre_plane_update(state);
7336
7337 intel_modeset_verify_disabled(state);
7338 }
7339
7340 intel_sagv_pre_plane_update(state);
7341
7342 /* Complete the events for pipes that have now been disabled */
7343 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7344 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
7345
7346 /* Complete events for now disable pipes here. */
7347 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) {
7348 spin_lock_irq(&display->drm->event_lock);
7349 drm_crtc_send_vblank_event(&crtc->base,
7350 new_crtc_state->uapi.event);
7351 spin_unlock_irq(&display->drm->event_lock);
7352
7353 new_crtc_state->uapi.event = NULL;
7354 }
7355 }
7356
7357 intel_encoders_update_prepare(state);
7358
7359 intel_dbuf_pre_plane_update(state);
7360
7361 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7362 if (new_crtc_state->do_async_flip)
7363 intel_crtc_enable_flip_done(state, crtc);
7364 }
7365
7366 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
7367 display->funcs.display->commit_modeset_enables(state);
7368
7369 intel_program_dpkgc_latency(state);
7370
7371 intel_wait_for_vblank_workers(state);
7372
7373 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
7374 * already, but still need the state for the delayed optimization. To
7375 * fix this:
7376 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
7377 * - schedule that vblank worker _before_ calling hw_done
7378 * - at the start of commit_tail, cancel it _synchrously
7379 * - switch over to the vblank wait helper in the core after that since
7380 * we don't need out special handling any more.
7381 */
7382 drm_atomic_helper_wait_for_flip_done(display->drm, &state->base);
7383
7384 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7385 if (new_crtc_state->do_async_flip)
7386 intel_crtc_disable_flip_done(state, crtc);
7387
7388 intel_atomic_dsb_wait_commit(new_crtc_state);
7389
7390 if (!state->base.legacy_cursor_update && !new_crtc_state->use_dsb)
7391 intel_vrr_check_push_sent(NULL, new_crtc_state);
7392 }
7393
7394 /*
7395 * Now that the vblank has passed, we can go ahead and program the
7396 * optimal watermarks on platforms that need two-step watermark
7397 * programming.
7398 *
7399 * TODO: Move this (and other cleanup) to an async worker eventually.
7400 */
7401 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7402 new_crtc_state, i) {
7403 /*
7404 * Gen2 reports pipe underruns whenever all planes are disabled.
7405 * So re-enable underrun reporting after some planes get enabled.
7406 *
7407 * We do this before .optimize_watermarks() so that we have a
7408 * chance of catching underruns with the intermediate watermarks
7409 * vs. the new plane configuration.
7410 */
7411 if (DISPLAY_VER(display) == 2 && planes_enabling(old_crtc_state, new_crtc_state))
7412 intel_set_cpu_fifo_underrun_reporting(display, crtc->pipe, true);
7413
7414 intel_optimize_watermarks(state, crtc);
7415 }
7416
7417 intel_dbuf_post_plane_update(state);
7418
7419 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
7420 intel_post_plane_update(state, crtc);
7421
7422 intel_modeset_put_crtc_power_domains(crtc, &put_domains[crtc->pipe]);
7423
7424 intel_modeset_verify_crtc(state, crtc);
7425
7426 intel_post_plane_update_after_readout(state, crtc);
7427
7428 /*
7429 * DSB cleanup is done in cleanup_work aligning with framebuffer
7430 * cleanup. So copy and reset the dsb structure to sync with
7431 * commit_done and later do dsb cleanup in cleanup_work.
7432 *
7433 * FIXME get rid of this funny new->old swapping
7434 */
7435 old_crtc_state->dsb_color_vblank = fetch_and_zero(&new_crtc_state->dsb_color_vblank);
7436 old_crtc_state->dsb_commit = fetch_and_zero(&new_crtc_state->dsb_commit);
7437 }
7438
7439 /* Underruns don't always raise interrupts, so check manually */
7440 intel_check_cpu_fifo_underruns(display);
7441 intel_check_pch_fifo_underruns(display);
7442
7443 if (state->modeset)
7444 intel_verify_planes(state);
7445
7446 intel_sagv_post_plane_update(state);
7447 if (state->modeset)
7448 intel_set_cdclk_post_plane_update(state);
7449 intel_pmdemand_post_plane_update(state);
7450
7451 drm_atomic_helper_commit_hw_done(&state->base);
7452 intel_atomic_global_state_commit_done(state);
7453
7454 if (state->modeset) {
7455 /* As one of the primary mmio accessors, KMS has a high
7456 * likelihood of triggering bugs in unclaimed access. After we
7457 * finish modesetting, see if an error has been flagged, and if
7458 * so enable debugging for the next modeset - and hope we catch
7459 * the culprit.
7460 */
7461 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
7462 }
7463 /*
7464 * Delay re-enabling DC states by 17 ms to avoid the off->on->off
7465 * toggling overhead at and above 60 FPS.
7466 */
7467 intel_display_power_put_async_delay(display, POWER_DOMAIN_DC_OFF, wakeref, 17);
7468 intel_display_rpm_put(display, state->wakeref);
7469
7470 /*
7471 * Defer the cleanup of the old state to a separate worker to not
7472 * impede the current task (userspace for blocking modesets) that
7473 * are executed inline. For out-of-line asynchronous modesets/flips,
7474 * deferring to a new worker seems overkill, but we would place a
7475 * schedule point (cond_resched()) here anyway to keep latencies
7476 * down.
7477 */
7478 INIT_WORK(&state->cleanup_work, intel_atomic_cleanup_work);
7479 queue_work(display->wq.cleanup, &state->cleanup_work);
7480 }
7481
intel_atomic_commit_work(struct work_struct * work)7482 static void intel_atomic_commit_work(struct work_struct *work)
7483 {
7484 struct intel_atomic_state *state =
7485 container_of(work, struct intel_atomic_state, base.commit_work);
7486
7487 intel_atomic_commit_tail(state);
7488 }
7489
intel_atomic_track_fbs(struct intel_atomic_state * state)7490 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
7491 {
7492 struct intel_plane_state *old_plane_state, *new_plane_state;
7493 struct intel_plane *plane;
7494 int i;
7495
7496 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
7497 new_plane_state, i)
7498 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
7499 to_intel_frontbuffer(new_plane_state->hw.fb),
7500 plane->frontbuffer_bit);
7501 }
7502
intel_atomic_setup_commit(struct intel_atomic_state * state,bool nonblock)7503 static int intel_atomic_setup_commit(struct intel_atomic_state *state, bool nonblock)
7504 {
7505 int ret;
7506
7507 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
7508 if (ret)
7509 return ret;
7510
7511 ret = intel_atomic_global_state_setup_commit(state);
7512 if (ret)
7513 return ret;
7514
7515 return 0;
7516 }
7517
intel_atomic_swap_state(struct intel_atomic_state * state)7518 static int intel_atomic_swap_state(struct intel_atomic_state *state)
7519 {
7520 int ret;
7521
7522 ret = drm_atomic_helper_swap_state(&state->base, true);
7523 if (ret)
7524 return ret;
7525
7526 intel_atomic_swap_global_state(state);
7527
7528 intel_shared_dpll_swap_state(state);
7529
7530 intel_atomic_track_fbs(state);
7531
7532 return 0;
7533 }
7534
intel_atomic_commit(struct drm_device * dev,struct drm_atomic_state * _state,bool nonblock)7535 int intel_atomic_commit(struct drm_device *dev, struct drm_atomic_state *_state,
7536 bool nonblock)
7537 {
7538 struct intel_display *display = to_intel_display(dev);
7539 struct intel_atomic_state *state = to_intel_atomic_state(_state);
7540 int ret = 0;
7541
7542 state->wakeref = intel_display_rpm_get(display);
7543
7544 /*
7545 * The intel_legacy_cursor_update() fast path takes care
7546 * of avoiding the vblank waits for simple cursor
7547 * movement and flips. For cursor on/off and size changes,
7548 * we want to perform the vblank waits so that watermark
7549 * updates happen during the correct frames. Gen9+ have
7550 * double buffered watermarks and so shouldn't need this.
7551 *
7552 * Unset state->legacy_cursor_update before the call to
7553 * drm_atomic_helper_setup_commit() because otherwise
7554 * drm_atomic_helper_wait_for_flip_done() is a noop and
7555 * we get FIFO underruns because we didn't wait
7556 * for vblank.
7557 *
7558 * FIXME doing watermarks and fb cleanup from a vblank worker
7559 * (assuming we had any) would solve these problems.
7560 */
7561 if (DISPLAY_VER(display) < 9 && state->base.legacy_cursor_update) {
7562 struct intel_crtc_state *new_crtc_state;
7563 struct intel_crtc *crtc;
7564 int i;
7565
7566 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7567 if (new_crtc_state->wm.need_postvbl_update ||
7568 new_crtc_state->update_wm_post)
7569 state->base.legacy_cursor_update = false;
7570 }
7571
7572 ret = intel_atomic_prepare_commit(state);
7573 if (ret) {
7574 drm_dbg_atomic(display->drm,
7575 "Preparing state failed with %i\n", ret);
7576 intel_display_rpm_put(display, state->wakeref);
7577 return ret;
7578 }
7579
7580 ret = intel_atomic_setup_commit(state, nonblock);
7581 if (!ret)
7582 ret = intel_atomic_swap_state(state);
7583
7584 if (ret) {
7585 drm_atomic_helper_unprepare_planes(dev, &state->base);
7586 intel_display_rpm_put(display, state->wakeref);
7587 return ret;
7588 }
7589
7590 drm_atomic_state_get(&state->base);
7591 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
7592
7593 if (nonblock && state->modeset) {
7594 queue_work(display->wq.modeset, &state->base.commit_work);
7595 } else if (nonblock) {
7596 queue_work(display->wq.flip, &state->base.commit_work);
7597 } else {
7598 if (state->modeset)
7599 flush_workqueue(display->wq.modeset);
7600 intel_atomic_commit_tail(state);
7601 }
7602
7603 return 0;
7604 }
7605
intel_encoder_possible_clones(struct intel_encoder * encoder)7606 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder)
7607 {
7608 struct intel_display *display = to_intel_display(encoder);
7609 struct intel_encoder *source_encoder;
7610 u32 possible_clones = 0;
7611
7612 for_each_intel_encoder(display->drm, source_encoder) {
7613 if (encoders_cloneable(encoder, source_encoder))
7614 possible_clones |= drm_encoder_mask(&source_encoder->base);
7615 }
7616
7617 return possible_clones;
7618 }
7619
intel_encoder_possible_crtcs(struct intel_encoder * encoder)7620 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder)
7621 {
7622 struct intel_display *display = to_intel_display(encoder);
7623 struct intel_crtc *crtc;
7624 u32 possible_crtcs = 0;
7625
7626 for_each_intel_crtc_in_pipe_mask(display->drm, crtc, encoder->pipe_mask)
7627 possible_crtcs |= drm_crtc_mask(&crtc->base);
7628
7629 return possible_crtcs;
7630 }
7631
ilk_has_edp_a(struct intel_display * display)7632 static bool ilk_has_edp_a(struct intel_display *display)
7633 {
7634 if (!display->platform.mobile)
7635 return false;
7636
7637 if ((intel_de_read(display, DP_A) & DP_DETECTED) == 0)
7638 return false;
7639
7640 if (display->platform.ironlake && (intel_de_read(display, FUSE_STRAP) & ILK_eDP_A_DISABLE))
7641 return false;
7642
7643 return true;
7644 }
7645
intel_ddi_crt_present(struct intel_display * display)7646 static bool intel_ddi_crt_present(struct intel_display *display)
7647 {
7648 if (DISPLAY_VER(display) >= 9)
7649 return false;
7650
7651 if (display->platform.haswell_ult || display->platform.broadwell_ult)
7652 return false;
7653
7654 if (HAS_PCH_LPT_H(display) &&
7655 intel_de_read(display, SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
7656 return false;
7657
7658 /* DDI E can't be used if DDI A requires 4 lanes */
7659 if (intel_de_read(display, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
7660 return false;
7661
7662 if (!display->vbt.int_crt_support)
7663 return false;
7664
7665 return true;
7666 }
7667
assert_port_valid(struct intel_display * display,enum port port)7668 bool assert_port_valid(struct intel_display *display, enum port port)
7669 {
7670 return !drm_WARN(display->drm, !(DISPLAY_RUNTIME_INFO(display)->port_mask & BIT(port)),
7671 "Platform does not support port %c\n", port_name(port));
7672 }
7673
intel_setup_outputs(struct intel_display * display)7674 void intel_setup_outputs(struct intel_display *display)
7675 {
7676 struct intel_encoder *encoder;
7677 bool dpd_is_edp = false;
7678
7679 intel_pps_unlock_regs_wa(display);
7680
7681 if (!HAS_DISPLAY(display))
7682 return;
7683
7684 if (HAS_DDI(display)) {
7685 if (intel_ddi_crt_present(display))
7686 intel_crt_init(display);
7687
7688 intel_bios_for_each_encoder(display, intel_ddi_init);
7689
7690 if (display->platform.geminilake || display->platform.broxton)
7691 vlv_dsi_init(display);
7692 } else if (HAS_PCH_SPLIT(display)) {
7693 int found;
7694
7695 /*
7696 * intel_edp_init_connector() depends on this completing first,
7697 * to prevent the registration of both eDP and LVDS and the
7698 * incorrect sharing of the PPS.
7699 */
7700 intel_lvds_init(display);
7701 intel_crt_init(display);
7702
7703 dpd_is_edp = intel_dp_is_port_edp(display, PORT_D);
7704
7705 if (ilk_has_edp_a(display))
7706 g4x_dp_init(display, DP_A, PORT_A);
7707
7708 if (intel_de_read(display, PCH_HDMIB) & SDVO_DETECTED) {
7709 /* PCH SDVOB multiplex with HDMIB */
7710 found = intel_sdvo_init(display, PCH_SDVOB, PORT_B);
7711 if (!found)
7712 g4x_hdmi_init(display, PCH_HDMIB, PORT_B);
7713 if (!found && (intel_de_read(display, PCH_DP_B) & DP_DETECTED))
7714 g4x_dp_init(display, PCH_DP_B, PORT_B);
7715 }
7716
7717 if (intel_de_read(display, PCH_HDMIC) & SDVO_DETECTED)
7718 g4x_hdmi_init(display, PCH_HDMIC, PORT_C);
7719
7720 if (!dpd_is_edp && intel_de_read(display, PCH_HDMID) & SDVO_DETECTED)
7721 g4x_hdmi_init(display, PCH_HDMID, PORT_D);
7722
7723 if (intel_de_read(display, PCH_DP_C) & DP_DETECTED)
7724 g4x_dp_init(display, PCH_DP_C, PORT_C);
7725
7726 if (intel_de_read(display, PCH_DP_D) & DP_DETECTED)
7727 g4x_dp_init(display, PCH_DP_D, PORT_D);
7728 } else if (display->platform.valleyview || display->platform.cherryview) {
7729 bool has_edp, has_port;
7730
7731 if (display->platform.valleyview && display->vbt.int_crt_support)
7732 intel_crt_init(display);
7733
7734 /*
7735 * The DP_DETECTED bit is the latched state of the DDC
7736 * SDA pin at boot. However since eDP doesn't require DDC
7737 * (no way to plug in a DP->HDMI dongle) the DDC pins for
7738 * eDP ports may have been muxed to an alternate function.
7739 * Thus we can't rely on the DP_DETECTED bit alone to detect
7740 * eDP ports. Consult the VBT as well as DP_DETECTED to
7741 * detect eDP ports.
7742 *
7743 * Sadly the straps seem to be missing sometimes even for HDMI
7744 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
7745 * and VBT for the presence of the port. Additionally we can't
7746 * trust the port type the VBT declares as we've seen at least
7747 * HDMI ports that the VBT claim are DP or eDP.
7748 */
7749 has_edp = intel_dp_is_port_edp(display, PORT_B);
7750 has_port = intel_bios_is_port_present(display, PORT_B);
7751 if (intel_de_read(display, VLV_DP_B) & DP_DETECTED || has_port)
7752 has_edp &= g4x_dp_init(display, VLV_DP_B, PORT_B);
7753 if ((intel_de_read(display, VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
7754 g4x_hdmi_init(display, VLV_HDMIB, PORT_B);
7755
7756 has_edp = intel_dp_is_port_edp(display, PORT_C);
7757 has_port = intel_bios_is_port_present(display, PORT_C);
7758 if (intel_de_read(display, VLV_DP_C) & DP_DETECTED || has_port)
7759 has_edp &= g4x_dp_init(display, VLV_DP_C, PORT_C);
7760 if ((intel_de_read(display, VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
7761 g4x_hdmi_init(display, VLV_HDMIC, PORT_C);
7762
7763 if (display->platform.cherryview) {
7764 /*
7765 * eDP not supported on port D,
7766 * so no need to worry about it
7767 */
7768 has_port = intel_bios_is_port_present(display, PORT_D);
7769 if (intel_de_read(display, CHV_DP_D) & DP_DETECTED || has_port)
7770 g4x_dp_init(display, CHV_DP_D, PORT_D);
7771 if (intel_de_read(display, CHV_HDMID) & SDVO_DETECTED || has_port)
7772 g4x_hdmi_init(display, CHV_HDMID, PORT_D);
7773 }
7774
7775 vlv_dsi_init(display);
7776 } else if (display->platform.pineview) {
7777 intel_lvds_init(display);
7778 intel_crt_init(display);
7779 } else if (IS_DISPLAY_VER(display, 3, 4)) {
7780 bool found = false;
7781
7782 if (display->platform.mobile)
7783 intel_lvds_init(display);
7784
7785 intel_crt_init(display);
7786
7787 if (intel_de_read(display, GEN3_SDVOB) & SDVO_DETECTED) {
7788 drm_dbg_kms(display->drm, "probing SDVOB\n");
7789 found = intel_sdvo_init(display, GEN3_SDVOB, PORT_B);
7790 if (!found && display->platform.g4x) {
7791 drm_dbg_kms(display->drm,
7792 "probing HDMI on SDVOB\n");
7793 g4x_hdmi_init(display, GEN4_HDMIB, PORT_B);
7794 }
7795
7796 if (!found && display->platform.g4x)
7797 g4x_dp_init(display, DP_B, PORT_B);
7798 }
7799
7800 /* Before G4X SDVOC doesn't have its own detect register */
7801
7802 if (intel_de_read(display, GEN3_SDVOB) & SDVO_DETECTED) {
7803 drm_dbg_kms(display->drm, "probing SDVOC\n");
7804 found = intel_sdvo_init(display, GEN3_SDVOC, PORT_C);
7805 }
7806
7807 if (!found && (intel_de_read(display, GEN3_SDVOC) & SDVO_DETECTED)) {
7808
7809 if (display->platform.g4x) {
7810 drm_dbg_kms(display->drm,
7811 "probing HDMI on SDVOC\n");
7812 g4x_hdmi_init(display, GEN4_HDMIC, PORT_C);
7813 }
7814 if (display->platform.g4x)
7815 g4x_dp_init(display, DP_C, PORT_C);
7816 }
7817
7818 if (display->platform.g4x && (intel_de_read(display, DP_D) & DP_DETECTED))
7819 g4x_dp_init(display, DP_D, PORT_D);
7820
7821 if (SUPPORTS_TV(display))
7822 intel_tv_init(display);
7823 } else if (DISPLAY_VER(display) == 2) {
7824 if (display->platform.i85x)
7825 intel_lvds_init(display);
7826
7827 intel_crt_init(display);
7828 intel_dvo_init(display);
7829 }
7830
7831 for_each_intel_encoder(display->drm, encoder) {
7832 encoder->base.possible_crtcs =
7833 intel_encoder_possible_crtcs(encoder);
7834 encoder->base.possible_clones =
7835 intel_encoder_possible_clones(encoder);
7836 }
7837
7838 intel_init_pch_refclk(display);
7839
7840 drm_helper_move_panel_connectors_to_head(display->drm);
7841 }
7842
max_dotclock(struct intel_display * display)7843 static int max_dotclock(struct intel_display *display)
7844 {
7845 int max_dotclock = display->cdclk.max_dotclk_freq;
7846
7847 if (HAS_ULTRAJOINER(display))
7848 max_dotclock *= 4;
7849 else if (HAS_UNCOMPRESSED_JOINER(display) || HAS_BIGJOINER(display))
7850 max_dotclock *= 2;
7851
7852 return max_dotclock;
7853 }
7854
intel_mode_valid(struct drm_device * dev,const struct drm_display_mode * mode)7855 enum drm_mode_status intel_mode_valid(struct drm_device *dev,
7856 const struct drm_display_mode *mode)
7857 {
7858 struct intel_display *display = to_intel_display(dev);
7859 int hdisplay_max, htotal_max;
7860 int vdisplay_max, vtotal_max;
7861
7862 /*
7863 * Can't reject DBLSCAN here because Xorg ddxen can add piles
7864 * of DBLSCAN modes to the output's mode list when they detect
7865 * the scaling mode property on the connector. And they don't
7866 * ask the kernel to validate those modes in any way until
7867 * modeset time at which point the client gets a protocol error.
7868 * So in order to not upset those clients we silently ignore the
7869 * DBLSCAN flag on such connectors. For other connectors we will
7870 * reject modes with the DBLSCAN flag in encoder->compute_config().
7871 * And we always reject DBLSCAN modes in connector->mode_valid()
7872 * as we never want such modes on the connector's mode list.
7873 */
7874
7875 if (mode->vscan > 1)
7876 return MODE_NO_VSCAN;
7877
7878 if (mode->flags & DRM_MODE_FLAG_HSKEW)
7879 return MODE_H_ILLEGAL;
7880
7881 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
7882 DRM_MODE_FLAG_NCSYNC |
7883 DRM_MODE_FLAG_PCSYNC))
7884 return MODE_HSYNC;
7885
7886 if (mode->flags & (DRM_MODE_FLAG_BCAST |
7887 DRM_MODE_FLAG_PIXMUX |
7888 DRM_MODE_FLAG_CLKDIV2))
7889 return MODE_BAD;
7890
7891 /*
7892 * Reject clearly excessive dotclocks early to
7893 * avoid having to worry about huge integers later.
7894 */
7895 if (mode->clock > max_dotclock(display))
7896 return MODE_CLOCK_HIGH;
7897
7898 /* Transcoder timing limits */
7899 if (DISPLAY_VER(display) >= 11) {
7900 hdisplay_max = 16384;
7901 vdisplay_max = 8192;
7902 htotal_max = 16384;
7903 vtotal_max = 8192;
7904 } else if (DISPLAY_VER(display) >= 9 ||
7905 display->platform.broadwell || display->platform.haswell) {
7906 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
7907 vdisplay_max = 4096;
7908 htotal_max = 8192;
7909 vtotal_max = 8192;
7910 } else if (DISPLAY_VER(display) >= 3) {
7911 hdisplay_max = 4096;
7912 vdisplay_max = 4096;
7913 htotal_max = 8192;
7914 vtotal_max = 8192;
7915 } else {
7916 hdisplay_max = 2048;
7917 vdisplay_max = 2048;
7918 htotal_max = 4096;
7919 vtotal_max = 4096;
7920 }
7921
7922 if (mode->hdisplay > hdisplay_max ||
7923 mode->hsync_start > htotal_max ||
7924 mode->hsync_end > htotal_max ||
7925 mode->htotal > htotal_max)
7926 return MODE_H_ILLEGAL;
7927
7928 if (mode->vdisplay > vdisplay_max ||
7929 mode->vsync_start > vtotal_max ||
7930 mode->vsync_end > vtotal_max ||
7931 mode->vtotal > vtotal_max)
7932 return MODE_V_ILLEGAL;
7933
7934 return MODE_OK;
7935 }
7936
intel_cpu_transcoder_mode_valid(struct intel_display * display,const struct drm_display_mode * mode)7937 enum drm_mode_status intel_cpu_transcoder_mode_valid(struct intel_display *display,
7938 const struct drm_display_mode *mode)
7939 {
7940 /*
7941 * Additional transcoder timing limits,
7942 * excluding BXT/GLK DSI transcoders.
7943 */
7944 if (DISPLAY_VER(display) >= 5) {
7945 if (mode->hdisplay < 64 ||
7946 mode->htotal - mode->hdisplay < 32)
7947 return MODE_H_ILLEGAL;
7948
7949 if (mode->vtotal - mode->vdisplay < 5)
7950 return MODE_V_ILLEGAL;
7951 } else {
7952 if (mode->htotal - mode->hdisplay < 32)
7953 return MODE_H_ILLEGAL;
7954
7955 if (mode->vtotal - mode->vdisplay < 3)
7956 return MODE_V_ILLEGAL;
7957 }
7958
7959 /*
7960 * Cantiga+ cannot handle modes with a hsync front porch of 0.
7961 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
7962 */
7963 if ((DISPLAY_VER(display) >= 5 || display->platform.g4x) &&
7964 mode->hsync_start == mode->hdisplay)
7965 return MODE_H_ILLEGAL;
7966
7967 return MODE_OK;
7968 }
7969
7970 enum drm_mode_status
intel_mode_valid_max_plane_size(struct intel_display * display,const struct drm_display_mode * mode,int num_joined_pipes)7971 intel_mode_valid_max_plane_size(struct intel_display *display,
7972 const struct drm_display_mode *mode,
7973 int num_joined_pipes)
7974 {
7975 int plane_width_max, plane_height_max;
7976
7977 /*
7978 * intel_mode_valid() should be
7979 * sufficient on older platforms.
7980 */
7981 if (DISPLAY_VER(display) < 9)
7982 return MODE_OK;
7983
7984 /*
7985 * Most people will probably want a fullscreen
7986 * plane so let's not advertize modes that are
7987 * too big for that.
7988 */
7989 if (DISPLAY_VER(display) >= 30) {
7990 plane_width_max = 6144 * num_joined_pipes;
7991 plane_height_max = 4800;
7992 } else if (DISPLAY_VER(display) >= 11) {
7993 plane_width_max = 5120 * num_joined_pipes;
7994 plane_height_max = 4320;
7995 } else {
7996 plane_width_max = 5120;
7997 plane_height_max = 4096;
7998 }
7999
8000 if (mode->hdisplay > plane_width_max)
8001 return MODE_H_ILLEGAL;
8002
8003 if (mode->vdisplay > plane_height_max)
8004 return MODE_V_ILLEGAL;
8005
8006 return MODE_OK;
8007 }
8008
8009 static const struct intel_display_funcs skl_display_funcs = {
8010 .get_pipe_config = hsw_get_pipe_config,
8011 .crtc_enable = hsw_crtc_enable,
8012 .crtc_disable = hsw_crtc_disable,
8013 .commit_modeset_enables = skl_commit_modeset_enables,
8014 .get_initial_plane_config = skl_get_initial_plane_config,
8015 .fixup_initial_plane_config = skl_fixup_initial_plane_config,
8016 };
8017
8018 static const struct intel_display_funcs ddi_display_funcs = {
8019 .get_pipe_config = hsw_get_pipe_config,
8020 .crtc_enable = hsw_crtc_enable,
8021 .crtc_disable = hsw_crtc_disable,
8022 .commit_modeset_enables = intel_commit_modeset_enables,
8023 .get_initial_plane_config = i9xx_get_initial_plane_config,
8024 .fixup_initial_plane_config = i9xx_fixup_initial_plane_config,
8025 };
8026
8027 static const struct intel_display_funcs pch_split_display_funcs = {
8028 .get_pipe_config = ilk_get_pipe_config,
8029 .crtc_enable = ilk_crtc_enable,
8030 .crtc_disable = ilk_crtc_disable,
8031 .commit_modeset_enables = intel_commit_modeset_enables,
8032 .get_initial_plane_config = i9xx_get_initial_plane_config,
8033 .fixup_initial_plane_config = i9xx_fixup_initial_plane_config,
8034 };
8035
8036 static const struct intel_display_funcs vlv_display_funcs = {
8037 .get_pipe_config = i9xx_get_pipe_config,
8038 .crtc_enable = valleyview_crtc_enable,
8039 .crtc_disable = i9xx_crtc_disable,
8040 .commit_modeset_enables = intel_commit_modeset_enables,
8041 .get_initial_plane_config = i9xx_get_initial_plane_config,
8042 .fixup_initial_plane_config = i9xx_fixup_initial_plane_config,
8043 };
8044
8045 static const struct intel_display_funcs i9xx_display_funcs = {
8046 .get_pipe_config = i9xx_get_pipe_config,
8047 .crtc_enable = i9xx_crtc_enable,
8048 .crtc_disable = i9xx_crtc_disable,
8049 .commit_modeset_enables = intel_commit_modeset_enables,
8050 .get_initial_plane_config = i9xx_get_initial_plane_config,
8051 .fixup_initial_plane_config = i9xx_fixup_initial_plane_config,
8052 };
8053
8054 /**
8055 * intel_init_display_hooks - initialize the display modesetting hooks
8056 * @display: display device private
8057 */
intel_init_display_hooks(struct intel_display * display)8058 void intel_init_display_hooks(struct intel_display *display)
8059 {
8060 if (DISPLAY_VER(display) >= 9) {
8061 display->funcs.display = &skl_display_funcs;
8062 } else if (HAS_DDI(display)) {
8063 display->funcs.display = &ddi_display_funcs;
8064 } else if (HAS_PCH_SPLIT(display)) {
8065 display->funcs.display = &pch_split_display_funcs;
8066 } else if (display->platform.cherryview ||
8067 display->platform.valleyview) {
8068 display->funcs.display = &vlv_display_funcs;
8069 } else {
8070 display->funcs.display = &i9xx_display_funcs;
8071 }
8072 }
8073
intel_initial_commit(struct intel_display * display)8074 int intel_initial_commit(struct intel_display *display)
8075 {
8076 struct drm_atomic_state *state = NULL;
8077 struct drm_modeset_acquire_ctx ctx;
8078 struct intel_crtc *crtc;
8079 int ret = 0;
8080
8081 state = drm_atomic_state_alloc(display->drm);
8082 if (!state)
8083 return -ENOMEM;
8084
8085 drm_modeset_acquire_init(&ctx, 0);
8086
8087 state->acquire_ctx = &ctx;
8088 to_intel_atomic_state(state)->internal = true;
8089
8090 retry:
8091 for_each_intel_crtc(display->drm, crtc) {
8092 struct intel_crtc_state *crtc_state =
8093 intel_atomic_get_crtc_state(state, crtc);
8094
8095 if (IS_ERR(crtc_state)) {
8096 ret = PTR_ERR(crtc_state);
8097 goto out;
8098 }
8099
8100 if (!crtc_state->hw.active)
8101 crtc_state->inherited = false;
8102
8103 if (crtc_state->hw.active) {
8104 struct intel_encoder *encoder;
8105
8106 ret = drm_atomic_add_affected_planes(state, &crtc->base);
8107 if (ret)
8108 goto out;
8109
8110 /*
8111 * FIXME hack to force a LUT update to avoid the
8112 * plane update forcing the pipe gamma on without
8113 * having a proper LUT loaded. Remove once we
8114 * have readout for pipe gamma enable.
8115 */
8116 crtc_state->uapi.color_mgmt_changed = true;
8117
8118 for_each_intel_encoder_mask(display->drm, encoder,
8119 crtc_state->uapi.encoder_mask) {
8120 if (encoder->initial_fastset_check &&
8121 !encoder->initial_fastset_check(encoder, crtc_state)) {
8122 ret = drm_atomic_add_affected_connectors(state,
8123 &crtc->base);
8124 if (ret)
8125 goto out;
8126 }
8127 }
8128 }
8129 }
8130
8131 ret = drm_atomic_commit(state);
8132
8133 out:
8134 if (ret == -EDEADLK) {
8135 drm_atomic_state_clear(state);
8136 drm_modeset_backoff(&ctx);
8137 goto retry;
8138 }
8139
8140 drm_atomic_state_put(state);
8141
8142 drm_modeset_drop_locks(&ctx);
8143 drm_modeset_acquire_fini(&ctx);
8144
8145 return ret;
8146 }
8147
i830_enable_pipe(struct intel_display * display,enum pipe pipe)8148 void i830_enable_pipe(struct intel_display *display, enum pipe pipe)
8149 {
8150 struct intel_crtc *crtc = intel_crtc_for_pipe(display, pipe);
8151 enum transcoder cpu_transcoder = (enum transcoder)pipe;
8152 /* 640x480@60Hz, ~25175 kHz */
8153 struct dpll clock = {
8154 .m1 = 18,
8155 .m2 = 7,
8156 .p1 = 13,
8157 .p2 = 4,
8158 .n = 2,
8159 };
8160 u32 dpll, fp;
8161 int i;
8162
8163 drm_WARN_ON(display->drm,
8164 i9xx_calc_dpll_params(48000, &clock) != 25154);
8165
8166 drm_dbg_kms(display->drm,
8167 "enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
8168 pipe_name(pipe), clock.vco, clock.dot);
8169
8170 fp = i9xx_dpll_compute_fp(&clock);
8171 dpll = DPLL_DVO_2X_MODE |
8172 DPLL_VGA_MODE_DIS |
8173 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
8174 PLL_P2_DIVIDE_BY_4 |
8175 PLL_REF_INPUT_DREFCLK |
8176 DPLL_VCO_ENABLE;
8177
8178 intel_de_write(display, TRANS_HTOTAL(display, cpu_transcoder),
8179 HACTIVE(640 - 1) | HTOTAL(800 - 1));
8180 intel_de_write(display, TRANS_HBLANK(display, cpu_transcoder),
8181 HBLANK_START(640 - 1) | HBLANK_END(800 - 1));
8182 intel_de_write(display, TRANS_HSYNC(display, cpu_transcoder),
8183 HSYNC_START(656 - 1) | HSYNC_END(752 - 1));
8184 intel_de_write(display, TRANS_VTOTAL(display, cpu_transcoder),
8185 VACTIVE(480 - 1) | VTOTAL(525 - 1));
8186 intel_de_write(display, TRANS_VBLANK(display, cpu_transcoder),
8187 VBLANK_START(480 - 1) | VBLANK_END(525 - 1));
8188 intel_de_write(display, TRANS_VSYNC(display, cpu_transcoder),
8189 VSYNC_START(490 - 1) | VSYNC_END(492 - 1));
8190 intel_de_write(display, PIPESRC(display, pipe),
8191 PIPESRC_WIDTH(640 - 1) | PIPESRC_HEIGHT(480 - 1));
8192
8193 intel_de_write(display, FP0(pipe), fp);
8194 intel_de_write(display, FP1(pipe), fp);
8195
8196 /*
8197 * Apparently we need to have VGA mode enabled prior to changing
8198 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
8199 * dividers, even though the register value does change.
8200 */
8201 intel_de_write(display, DPLL(display, pipe),
8202 dpll & ~DPLL_VGA_MODE_DIS);
8203 intel_de_write(display, DPLL(display, pipe), dpll);
8204
8205 /* Wait for the clocks to stabilize. */
8206 intel_de_posting_read(display, DPLL(display, pipe));
8207 udelay(150);
8208
8209 /* The pixel multiplier can only be updated once the
8210 * DPLL is enabled and the clocks are stable.
8211 *
8212 * So write it again.
8213 */
8214 intel_de_write(display, DPLL(display, pipe), dpll);
8215
8216 /* We do this three times for luck */
8217 for (i = 0; i < 3 ; i++) {
8218 intel_de_write(display, DPLL(display, pipe), dpll);
8219 intel_de_posting_read(display, DPLL(display, pipe));
8220 udelay(150); /* wait for warmup */
8221 }
8222
8223 intel_de_write(display, TRANSCONF(display, pipe), TRANSCONF_ENABLE);
8224 intel_de_posting_read(display, TRANSCONF(display, pipe));
8225
8226 intel_wait_for_pipe_scanline_moving(crtc);
8227 }
8228
i830_disable_pipe(struct intel_display * display,enum pipe pipe)8229 void i830_disable_pipe(struct intel_display *display, enum pipe pipe)
8230 {
8231 struct intel_crtc *crtc = intel_crtc_for_pipe(display, pipe);
8232
8233 drm_dbg_kms(display->drm, "disabling pipe %c due to force quirk\n",
8234 pipe_name(pipe));
8235
8236 drm_WARN_ON(display->drm,
8237 intel_de_read(display, DSPCNTR(display, PLANE_A)) & DISP_ENABLE);
8238 drm_WARN_ON(display->drm,
8239 intel_de_read(display, DSPCNTR(display, PLANE_B)) & DISP_ENABLE);
8240 drm_WARN_ON(display->drm,
8241 intel_de_read(display, DSPCNTR(display, PLANE_C)) & DISP_ENABLE);
8242 drm_WARN_ON(display->drm,
8243 intel_de_read(display, CURCNTR(display, PIPE_A)) & MCURSOR_MODE_MASK);
8244 drm_WARN_ON(display->drm,
8245 intel_de_read(display, CURCNTR(display, PIPE_B)) & MCURSOR_MODE_MASK);
8246
8247 intel_de_write(display, TRANSCONF(display, pipe), 0);
8248 intel_de_posting_read(display, TRANSCONF(display, pipe));
8249
8250 intel_wait_for_pipe_scanline_stopped(crtc);
8251
8252 intel_de_write(display, DPLL(display, pipe), DPLL_VGA_MODE_DIS);
8253 intel_de_posting_read(display, DPLL(display, pipe));
8254 }
8255
intel_scanout_needs_vtd_wa(struct intel_display * display)8256 bool intel_scanout_needs_vtd_wa(struct intel_display *display)
8257 {
8258 struct drm_i915_private *i915 = to_i915(display->drm);
8259
8260 return IS_DISPLAY_VER(display, 6, 11) && i915_vtd_active(i915);
8261 }
8262