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