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