xref: /linux/drivers/gpu/drm/i915/display/intel_display_driver.c (revision b718342a7fbaa2dff5fefc31988c07af8c6cbc21)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2022-2023 Intel Corporation
4  *
5  * High level display driver entry points. This is a layer between top level
6  * driver code and low level display functionality; no low level display code or
7  * details here.
8  */
9 
10 #include <linux/vga_switcheroo.h>
11 #include <acpi/video.h>
12 #include <drm/display/drm_dp_mst_helper.h>
13 #include <drm/drm_atomic_helper.h>
14 #include <drm/drm_client_event.h>
15 #include <drm/drm_mode_config.h>
16 #include <drm/drm_privacy_screen_consumer.h>
17 #include <drm/drm_print.h>
18 #include <drm/drm_probe_helper.h>
19 #include <drm/drm_vblank.h>
20 
21 #include "i9xx_wm.h"
22 #include "intel_acpi.h"
23 #include "intel_atomic.h"
24 #include "intel_audio.h"
25 #include "intel_bios.h"
26 #include "intel_bw.h"
27 #include "intel_cdclk.h"
28 #include "intel_color.h"
29 #include "intel_crtc.h"
30 #include "intel_cursor.h"
31 #include "intel_dbuf_bw.h"
32 #include "intel_display_core.h"
33 #include "intel_display_debugfs.h"
34 #include "intel_display_driver.h"
35 #include "intel_display_irq.h"
36 #include "intel_display_power.h"
37 #include "intel_display_types.h"
38 #include "intel_display_utils.h"
39 #include "intel_display_wa.h"
40 #include "intel_dkl_phy.h"
41 #include "intel_dmc.h"
42 #include "intel_dp.h"
43 #include "intel_dp_tunnel.h"
44 #include "intel_dpll.h"
45 #include "intel_dpll_mgr.h"
46 #include "intel_fb.h"
47 #include "intel_fbc.h"
48 #include "intel_fbdev.h"
49 #include "intel_fdi.h"
50 #include "intel_flipq.h"
51 #include "intel_gmbus.h"
52 #include "intel_hdcp.h"
53 #include "intel_hotplug.h"
54 #include "intel_hti.h"
55 #include "intel_initial_plane.h"
56 #include "intel_modeset_lock.h"
57 #include "intel_modeset_setup.h"
58 #include "intel_opregion.h"
59 #include "intel_overlay.h"
60 #include "intel_pmdemand.h"
61 #include "intel_pps.h"
62 #include "intel_psr.h"
63 #include "intel_quirks.h"
64 #include "intel_vga.h"
65 #include "intel_wm.h"
66 #include "skl_watermark.h"
67 
68 bool intel_display_driver_probe_defer(struct pci_dev *pdev)
69 {
70 	struct drm_privacy_screen *privacy_screen;
71 
72 	/*
73 	 * apple-gmux is needed on dual GPU MacBook Pro
74 	 * to probe the panel if we're the inactive GPU.
75 	 */
76 	if (vga_switcheroo_client_probe_defer(pdev))
77 		return true;
78 
79 	/* If the LCD panel has a privacy-screen, wait for it */
80 	privacy_screen = drm_privacy_screen_get(&pdev->dev, NULL);
81 	if (IS_ERR(privacy_screen) && PTR_ERR(privacy_screen) == -EPROBE_DEFER)
82 		return true;
83 
84 	drm_privacy_screen_put(privacy_screen);
85 
86 	return false;
87 }
88 
89 void intel_display_driver_init_hw(struct intel_display *display)
90 {
91 	if (!HAS_DISPLAY(display))
92 		return;
93 
94 	intel_cdclk_read_hw(display);
95 
96 	intel_display_wa_apply(display);
97 }
98 
99 static const struct drm_mode_config_funcs intel_mode_funcs = {
100 	.fb_create = intel_user_framebuffer_create,
101 	.get_format_info = intel_fb_get_format_info,
102 	.mode_valid = intel_mode_valid,
103 	.atomic_check = intel_atomic_check,
104 	.atomic_commit = intel_atomic_commit,
105 	.atomic_state_alloc = intel_atomic_state_alloc,
106 	.atomic_state_clear = intel_atomic_state_clear,
107 	.atomic_state_free = intel_atomic_state_free,
108 };
109 
110 static const struct drm_mode_config_helper_funcs intel_mode_config_funcs = {
111 	.atomic_commit_setup = drm_dp_mst_atomic_setup_commit,
112 };
113 
114 static void intel_mode_config_init(struct intel_display *display)
115 {
116 	struct drm_mode_config *mode_config = &display->drm->mode_config;
117 
118 	drm_mode_config_init(display->drm);
119 	INIT_LIST_HEAD(&display->global.obj_list);
120 	INIT_LIST_HEAD(&display->pipe_list);
121 
122 	mode_config->min_width = 0;
123 	mode_config->min_height = 0;
124 
125 	mode_config->preferred_depth = 24;
126 	mode_config->prefer_shadow = 1;
127 
128 	mode_config->funcs = &intel_mode_funcs;
129 	mode_config->helper_private = &intel_mode_config_funcs;
130 
131 	mode_config->async_page_flip = HAS_ASYNC_FLIPS(display);
132 
133 	/*
134 	 * Maximum framebuffer dimensions, chosen to match
135 	 * the maximum render engine surface size on gen4+.
136 	 */
137 	if (DISPLAY_VER(display) >= 7) {
138 		mode_config->max_width = 16384;
139 		mode_config->max_height = 16384;
140 	} else if (DISPLAY_VER(display) >= 4) {
141 		mode_config->max_width = 8192;
142 		mode_config->max_height = 8192;
143 	} else if (DISPLAY_VER(display) == 3) {
144 		mode_config->max_width = 4096;
145 		mode_config->max_height = 4096;
146 	} else {
147 		mode_config->max_width = 2048;
148 		mode_config->max_height = 2048;
149 	}
150 
151 	intel_cursor_mode_config_init(display);
152 }
153 
154 static void intel_mode_config_cleanup(struct intel_display *display)
155 {
156 	intel_atomic_global_obj_cleanup(display);
157 	drm_mode_config_cleanup(display->drm);
158 }
159 
160 static void intel_plane_possible_crtcs_init(struct intel_display *display)
161 {
162 	struct intel_plane *plane;
163 
164 	for_each_intel_plane(display->drm, plane) {
165 		struct intel_crtc *crtc = intel_crtc_for_pipe(display,
166 							      plane->pipe);
167 
168 		plane->base.possible_crtcs = drm_crtc_mask(&crtc->base);
169 	}
170 }
171 
172 void intel_display_driver_early_probe(struct intel_display *display)
173 {
174 	/* This must be called before any calls to HAS_PCH_* */
175 	intel_pch_detect(display);
176 
177 	if (!HAS_DISPLAY(display))
178 		return;
179 
180 	spin_lock_init(&display->fb_tracking.lock);
181 	mutex_init(&display->backlight.lock);
182 	mutex_init(&display->audio.mutex);
183 	mutex_init(&display->wm.wm_mutex);
184 	mutex_init(&display->pps.mutex);
185 	mutex_init(&display->hdcp.hdcp_mutex);
186 
187 	intel_display_irq_init(display);
188 	intel_dkl_phy_init(display);
189 	intel_color_init_hooks(display);
190 	intel_init_cdclk_hooks(display);
191 	intel_audio_hooks_init(display);
192 	intel_dpll_init_clock_hook(display);
193 	intel_init_display_hooks(display);
194 	intel_fdi_init_hook(display);
195 	intel_dmc_wl_init(display);
196 }
197 
198 /* part #1: call before irq install */
199 int intel_display_driver_probe_noirq(struct intel_display *display)
200 {
201 	int ret;
202 
203 	if (HAS_DISPLAY(display)) {
204 		ret = drm_vblank_init(display->drm,
205 				      INTEL_NUM_PIPES(display));
206 		if (ret)
207 			return ret;
208 	}
209 
210 	intel_bios_init(display);
211 
212 	intel_psr_dc5_dc6_wa_init(display);
213 
214 	/* FIXME: completely on the wrong abstraction layer */
215 	ret = intel_power_domains_init(display);
216 	if (ret < 0)
217 		goto cleanup_bios;
218 
219 	intel_pmdemand_init_early(display);
220 
221 	intel_power_domains_init_hw(display, false);
222 
223 	if (!HAS_DISPLAY(display))
224 		return 0;
225 
226 	display->hotplug.dp_wq = alloc_ordered_workqueue("intel-dp", 0);
227 	if (!display->hotplug.dp_wq) {
228 		ret = -ENOMEM;
229 		goto cleanup_pw_domain_dmc;
230 	}
231 
232 	display->wq.modeset = alloc_ordered_workqueue("i915_modeset", 0);
233 	if (!display->wq.modeset) {
234 		ret = -ENOMEM;
235 		goto cleanup_wq_dp;
236 	}
237 
238 	display->wq.flip = alloc_workqueue("i915_flip", WQ_HIGHPRI |
239 						WQ_UNBOUND, WQ_UNBOUND_MAX_ACTIVE);
240 	if (!display->wq.flip) {
241 		ret = -ENOMEM;
242 		goto cleanup_wq_modeset;
243 	}
244 
245 	display->wq.cleanup = alloc_workqueue("i915_cleanup", WQ_HIGHPRI | WQ_PERCPU, 0);
246 	if (!display->wq.cleanup) {
247 		ret = -ENOMEM;
248 		goto cleanup_wq_flip;
249 	}
250 
251 	display->wq.unordered = alloc_workqueue("display_unordered", WQ_PERCPU, 0);
252 	if (!display->wq.unordered) {
253 		ret = -ENOMEM;
254 		goto cleanup_wq_cleanup;
255 	}
256 
257 	intel_dmc_init(display);
258 
259 	intel_mode_config_init(display);
260 
261 	ret = intel_cdclk_init(display);
262 	if (ret)
263 		goto cleanup_wq_unordered;
264 
265 	ret = intel_color_init(display);
266 	if (ret)
267 		goto cleanup_wq_unordered;
268 
269 	ret = intel_dbuf_init(display);
270 	if (ret)
271 		goto cleanup_wq_unordered;
272 
273 	ret = intel_dbuf_bw_init(display);
274 	if (ret)
275 		goto cleanup_wq_unordered;
276 
277 	ret = intel_bw_init(display);
278 	if (ret)
279 		goto cleanup_wq_unordered;
280 
281 	ret = intel_pmdemand_init(display);
282 	if (ret)
283 		goto cleanup_wq_unordered;
284 
285 	intel_init_quirks(display);
286 
287 	intel_fbc_init(display);
288 
289 	return 0;
290 
291 cleanup_wq_unordered:
292 	destroy_workqueue(display->wq.unordered);
293 cleanup_wq_cleanup:
294 	destroy_workqueue(display->wq.cleanup);
295 cleanup_wq_flip:
296 	destroy_workqueue(display->wq.flip);
297 cleanup_wq_modeset:
298 	destroy_workqueue(display->wq.modeset);
299 cleanup_wq_dp:
300 	destroy_workqueue(display->hotplug.dp_wq);
301 cleanup_pw_domain_dmc:
302 	intel_dmc_fini(display);
303 	intel_power_domains_driver_remove(display);
304 cleanup_bios:
305 	intel_bios_driver_remove(display);
306 
307 	return ret;
308 }
309 ALLOW_ERROR_INJECTION(intel_display_driver_probe_noirq, ERRNO);
310 
311 static void set_display_access(struct intel_display *display,
312 			       bool any_task_allowed,
313 			       struct task_struct *allowed_task)
314 {
315 	struct drm_modeset_acquire_ctx ctx;
316 	int err;
317 
318 	intel_modeset_lock_ctx_retry(&ctx, NULL, 0, err) {
319 		err = drm_modeset_lock_all_ctx(display->drm, &ctx);
320 		if (err)
321 			continue;
322 
323 		display->access.any_task_allowed = any_task_allowed;
324 		display->access.allowed_task = allowed_task;
325 	}
326 
327 	drm_WARN_ON(display->drm, err);
328 }
329 
330 /**
331  * intel_display_driver_enable_user_access - Enable display HW access for all threads
332  * @display: display device instance
333  *
334  * Enable the display HW access for all threads. Examples for such accesses
335  * are modeset commits and connector probing.
336  *
337  * This function should be called during driver loading and system resume once
338  * all the HW initialization steps are done.
339  */
340 void intel_display_driver_enable_user_access(struct intel_display *display)
341 {
342 	set_display_access(display, true, NULL);
343 
344 	intel_hpd_enable_detection_work(display);
345 }
346 
347 /**
348  * intel_display_driver_disable_user_access - Disable display HW access for user threads
349  * @display: display device instance
350  *
351  * Disable the display HW access for user threads. Examples for such accesses
352  * are modeset commits and connector probing. For the current thread the
353  * access is still enabled, which should only perform HW init/deinit
354  * programming (as the initial modeset during driver loading or the disabling
355  * modeset during driver unloading and system suspend/shutdown). This function
356  * should be followed by calling either intel_display_driver_enable_user_access()
357  * after completing the HW init programming or
358  * intel_display_driver_suspend_access() after completing the HW deinit
359  * programming.
360  *
361  * This function should be called during driver loading/unloading and system
362  * suspend/shutdown before starting the HW init/deinit programming.
363  */
364 void intel_display_driver_disable_user_access(struct intel_display *display)
365 {
366 	intel_hpd_disable_detection_work(display);
367 
368 	set_display_access(display, false, current);
369 }
370 
371 /**
372  * intel_display_driver_suspend_access - Suspend display HW access for all threads
373  * @display: display device instance
374  *
375  * Disable the display HW access for all threads. Examples for such accesses
376  * are modeset commits and connector probing. This call should be either
377  * followed by calling intel_display_driver_resume_access(), or the driver
378  * should be unloaded/shutdown.
379  *
380  * This function should be called during driver unloading and system
381  * suspend/shutdown after completing the HW deinit programming.
382  */
383 void intel_display_driver_suspend_access(struct intel_display *display)
384 {
385 	set_display_access(display, false, NULL);
386 }
387 
388 /**
389  * intel_display_driver_resume_access - Resume display HW access for the resume thread
390  * @display: display device instance
391  *
392  * Enable the display HW access for the current resume thread, keeping the
393  * access disabled for all other (user) threads. Examples for such accesses
394  * are modeset commits and connector probing. The resume thread should only
395  * perform HW init programming (as the restoring modeset). This function
396  * should be followed by calling intel_display_driver_enable_user_access(),
397  * after completing the HW init programming steps.
398  *
399  * This function should be called during system resume before starting the HW
400  * init steps.
401  */
402 void intel_display_driver_resume_access(struct intel_display *display)
403 {
404 	set_display_access(display, false, current);
405 }
406 
407 /**
408  * intel_display_driver_check_access - Check if the current thread has disaplay HW access
409  * @display: display device instance
410  *
411  * Check whether the current thread has display HW access, print a debug
412  * message if it doesn't. Such accesses are modeset commits and connector
413  * probing. If the function returns %false any HW access should be prevented.
414  *
415  * Returns %true if the current thread has display HW access, %false
416  * otherwise.
417  */
418 bool intel_display_driver_check_access(struct intel_display *display)
419 {
420 	char current_task[TASK_COMM_LEN + 16];
421 	char allowed_task[TASK_COMM_LEN + 16] = "none";
422 
423 	if (display->access.any_task_allowed ||
424 	    display->access.allowed_task == current)
425 		return true;
426 
427 	snprintf(current_task, sizeof(current_task), "%s[%d]",
428 		 current->comm, task_pid_vnr(current));
429 
430 	if (display->access.allowed_task)
431 		snprintf(allowed_task, sizeof(allowed_task), "%s[%d]",
432 			 display->access.allowed_task->comm,
433 			 task_pid_vnr(display->access.allowed_task));
434 
435 	drm_dbg_kms(display->drm,
436 		    "Reject display access from task %s (allowed to %s)\n",
437 		    current_task, allowed_task);
438 
439 	return false;
440 }
441 
442 /* part #2: call after irq install, but before gem init */
443 int intel_display_driver_probe_nogem(struct intel_display *display)
444 {
445 	int ret;
446 
447 	if (!HAS_DISPLAY(display))
448 		return 0;
449 
450 	intel_wm_init(display);
451 
452 	intel_panel_sanitize_ssc(display);
453 
454 	intel_pps_setup(display);
455 
456 	intel_gmbus_setup(display);
457 
458 	ret = intel_crtc_init(display);
459 	if (ret)
460 		goto err_mode_config;
461 
462 	intel_plane_possible_crtcs_init(display);
463 	intel_dpll_init(display);
464 	intel_fdi_pll_freq_update(display);
465 
466 	intel_display_driver_init_hw(display);
467 	intel_dpll_update_ref_clks(display);
468 
469 	if (display->cdclk.max_cdclk_freq == 0)
470 		intel_update_max_cdclk(display);
471 
472 	intel_hti_init(display);
473 
474 	intel_setup_outputs(display);
475 
476 	ret = intel_dp_tunnel_mgr_init(display);
477 	if (ret)
478 		goto err_hdcp;
479 
480 	intel_display_driver_disable_user_access(display);
481 
482 	drm_modeset_lock_all(display->drm);
483 	intel_modeset_setup_hw_state(display, display->drm->mode_config.acquire_ctx);
484 	intel_acpi_assign_connector_fwnodes(display);
485 	drm_modeset_unlock_all(display->drm);
486 
487 	intel_initial_plane_config(display);
488 
489 	/*
490 	 * Make sure hardware watermarks really match the state we read out.
491 	 * Note that we need to do this after reconstructing the BIOS fb's
492 	 * since the watermark calculation done here will use pstate->fb.
493 	 */
494 	if (!HAS_GMCH(display))
495 		ilk_wm_sanitize(display);
496 
497 	return 0;
498 
499 err_hdcp:
500 	intel_hdcp_component_fini(display);
501 err_mode_config:
502 	intel_mode_config_cleanup(display);
503 
504 	return ret;
505 }
506 
507 /* part #3: call after gem init */
508 int intel_display_driver_probe(struct intel_display *display)
509 {
510 	int ret;
511 
512 	if (!HAS_DISPLAY(display))
513 		return 0;
514 
515 	/*
516 	 * This will bind stuff into ggtt, so it needs to be done after
517 	 * the BIOS fb takeover and whatever else magic ggtt reservations
518 	 * happen during gem/ggtt init.
519 	 */
520 	intel_hdcp_component_init(display);
521 
522 	intel_flipq_init(display);
523 
524 	/*
525 	 * Force all active planes to recompute their states. So that on
526 	 * mode_setcrtc after probe, all the intel_plane_state variables
527 	 * are already calculated and there is no assert_plane warnings
528 	 * during bootup.
529 	 */
530 	ret = intel_initial_commit(display);
531 	if (ret)
532 		drm_dbg_kms(display->drm, "Initial modeset failed, %d\n", ret);
533 
534 	intel_overlay_setup(display);
535 
536 	/* Only enable hotplug handling once the fbdev is fully set up. */
537 	intel_hpd_init(display);
538 
539 	skl_watermark_ipc_init(display);
540 
541 	return 0;
542 }
543 
544 void intel_display_driver_register(struct intel_display *display)
545 {
546 	struct drm_printer p = drm_dbg_printer(display->drm, DRM_UT_KMS,
547 					       "i915 display info:");
548 
549 	if (!HAS_DISPLAY(display))
550 		return;
551 
552 	intel_vga_register(display);
553 
554 	/* Must be done after probing outputs */
555 	intel_opregion_register(display);
556 	intel_acpi_video_register(display);
557 
558 	intel_audio_init(display);
559 
560 	intel_display_driver_enable_user_access(display);
561 
562 	intel_audio_register(display);
563 
564 	intel_display_debugfs_register(display);
565 
566 	/*
567 	 * We need to coordinate the hotplugs with the asynchronous
568 	 * fbdev configuration, for which we use the
569 	 * fbdev->async_cookie.
570 	 */
571 	drm_kms_helper_poll_init(display->drm);
572 	intel_hpd_poll_disable(display);
573 
574 	intel_fbdev_setup(display);
575 
576 	intel_display_device_info_print(DISPLAY_INFO(display),
577 					DISPLAY_RUNTIME_INFO(display), &p);
578 
579 	intel_register_dsm_handler();
580 }
581 
582 /* part #1: call before irq uninstall */
583 void intel_display_driver_remove(struct intel_display *display)
584 {
585 	if (!HAS_DISPLAY(display))
586 		return;
587 
588 	flush_workqueue(display->wq.flip);
589 	flush_workqueue(display->wq.modeset);
590 	flush_workqueue(display->wq.cleanup);
591 	flush_workqueue(display->wq.unordered);
592 
593 	/*
594 	 * MST topology needs to be suspended so we don't have any calls to
595 	 * fbdev after it's finalized. MST will be destroyed later as part of
596 	 * drm_mode_config_cleanup()
597 	 */
598 	intel_dp_mst_suspend(display);
599 }
600 
601 /* part #2: call after irq uninstall */
602 void intel_display_driver_remove_noirq(struct intel_display *display)
603 {
604 	if (!HAS_DISPLAY(display))
605 		return;
606 
607 	intel_display_driver_suspend_access(display);
608 
609 	/*
610 	 * Due to the hpd irq storm handling the hotplug work can re-arm the
611 	 * poll handlers. Hence disable polling after hpd handling is shut down.
612 	 */
613 	intel_hpd_poll_fini(display);
614 
615 	intel_unregister_dsm_handler();
616 
617 	/* flush any delayed tasks or pending work */
618 	flush_workqueue(display->wq.unordered);
619 
620 	intel_hdcp_component_fini(display);
621 
622 	intel_mode_config_cleanup(display);
623 
624 	intel_dp_tunnel_mgr_cleanup(display);
625 
626 	intel_overlay_cleanup(display);
627 
628 	intel_gmbus_teardown(display);
629 
630 	destroy_workqueue(display->hotplug.dp_wq);
631 	destroy_workqueue(display->wq.flip);
632 	destroy_workqueue(display->wq.modeset);
633 	destroy_workqueue(display->wq.cleanup);
634 	destroy_workqueue(display->wq.unordered);
635 
636 	intel_fbc_cleanup(display);
637 }
638 
639 /* part #3: call after gem init */
640 void intel_display_driver_remove_nogem(struct intel_display *display)
641 {
642 	intel_dmc_fini(display);
643 
644 	intel_power_domains_driver_remove(display);
645 
646 	intel_bios_driver_remove(display);
647 }
648 
649 void intel_display_driver_unregister(struct intel_display *display)
650 {
651 	if (!HAS_DISPLAY(display))
652 		return;
653 
654 	intel_unregister_dsm_handler();
655 
656 	drm_client_dev_unregister(display->drm);
657 
658 	/*
659 	 * After flushing the fbdev (incl. a late async config which
660 	 * will have delayed queuing of a hotplug event), then flush
661 	 * the hotplug events.
662 	 */
663 	drm_kms_helper_poll_fini(display->drm);
664 
665 	intel_display_driver_disable_user_access(display);
666 
667 	intel_audio_deinit(display);
668 
669 	drm_atomic_helper_shutdown(display->drm);
670 
671 	acpi_video_unregister();
672 	intel_opregion_unregister(display);
673 
674 	intel_vga_unregister(display);
675 }
676 
677 /*
678  * turn all crtc's off, but do not adjust state
679  * This has to be paired with a call to intel_modeset_setup_hw_state.
680  */
681 int intel_display_driver_suspend(struct intel_display *display)
682 {
683 	struct drm_atomic_state *state;
684 	int ret;
685 
686 	if (!HAS_DISPLAY(display))
687 		return 0;
688 
689 	state = drm_atomic_helper_suspend(display->drm);
690 	ret = PTR_ERR_OR_ZERO(state);
691 	if (ret)
692 		drm_err(display->drm, "Suspending crtc's failed with %i\n",
693 			ret);
694 	else
695 		display->restore.modeset_state = state;
696 
697 	/* ensure all DPT VMAs have been unpinned for intel_dpt_suspend() */
698 	flush_workqueue(display->wq.cleanup);
699 
700 	intel_dp_mst_suspend(display);
701 
702 	return ret;
703 }
704 
705 int
706 __intel_display_driver_resume(struct intel_display *display,
707 			      struct drm_atomic_state *state,
708 			      struct drm_modeset_acquire_ctx *ctx)
709 {
710 	struct drm_crtc_state *crtc_state;
711 	struct drm_crtc *crtc;
712 	int ret, i;
713 
714 	intel_modeset_setup_hw_state(display, ctx);
715 
716 	if (!state)
717 		return 0;
718 
719 	/*
720 	 * We've duplicated the state, pointers to the old state are invalid.
721 	 *
722 	 * Don't attempt to use the old state until we commit the duplicated state.
723 	 */
724 	for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
725 		/*
726 		 * Force recalculation even if we restore
727 		 * current state. With fast modeset this may not result
728 		 * in a modeset when the state is compatible.
729 		 */
730 		crtc_state->mode_changed = true;
731 	}
732 
733 	/* ignore any reset values/BIOS leftovers in the WM registers */
734 	if (!HAS_GMCH(display))
735 		to_intel_atomic_state(state)->skip_intermediate_wm = true;
736 
737 	ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
738 
739 	drm_WARN_ON(display->drm, ret == -EDEADLK);
740 
741 	return ret;
742 }
743 
744 void intel_display_driver_resume(struct intel_display *display)
745 {
746 	struct drm_atomic_state *state = display->restore.modeset_state;
747 	struct drm_modeset_acquire_ctx ctx;
748 	int ret;
749 
750 	if (!HAS_DISPLAY(display))
751 		return;
752 
753 	/* MST sideband requires HPD interrupts enabled */
754 	intel_dp_mst_resume(display);
755 
756 	display->restore.modeset_state = NULL;
757 	if (state)
758 		state->acquire_ctx = &ctx;
759 
760 	drm_modeset_acquire_init(&ctx, 0);
761 
762 	while (1) {
763 		ret = drm_modeset_lock_all_ctx(display->drm, &ctx);
764 		if (ret != -EDEADLK)
765 			break;
766 
767 		drm_modeset_backoff(&ctx);
768 	}
769 
770 	if (!ret)
771 		ret = __intel_display_driver_resume(display, state, &ctx);
772 
773 	skl_watermark_ipc_update(display);
774 	drm_modeset_drop_locks(&ctx);
775 	drm_modeset_acquire_fini(&ctx);
776 
777 	if (ret)
778 		drm_err(display->drm,
779 			"Restoring old state failed with %i\n", ret);
780 	if (state)
781 		drm_atomic_state_put(state);
782 }
783