1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2023 Intel Corporation 4 */ 5 6 #include <drm/drm_atomic_helper.h> 7 #include <drm/drm_print.h> 8 9 #include "i915_drv.h" 10 #include "intel_clock_gating.h" 11 #include "intel_cx0_phy.h" 12 #include "intel_display_core.h" 13 #include "intel_display_driver.h" 14 #include "intel_display_reset.h" 15 #include "intel_display_types.h" 16 #include "intel_hotplug.h" 17 #include "intel_pps.h" 18 19 bool intel_display_reset_test(struct intel_display *display) 20 { 21 return display->params.force_reset_modeset_test; 22 } 23 24 /* returns true if intel_display_reset_finish() needs to be called */ 25 bool intel_display_reset_prepare(struct intel_display *display, 26 modeset_stuck_fn modeset_stuck, void *context) 27 { 28 struct drm_modeset_acquire_ctx *ctx = &display->restore.reset_ctx; 29 struct drm_atomic_state *state; 30 int ret; 31 32 if (!HAS_DISPLAY(display)) 33 return false; 34 35 if (atomic_read(&display->restore.pending_fb_pin)) { 36 drm_dbg_kms(display->drm, 37 "Modeset potentially stuck, unbreaking through wedging\n"); 38 modeset_stuck(context); 39 } 40 41 /* 42 * Need mode_config.mutex so that we don't 43 * trample ongoing ->detect() and whatnot. 44 */ 45 mutex_lock(&display->drm->mode_config.mutex); 46 drm_modeset_acquire_init(ctx, 0); 47 while (1) { 48 ret = drm_modeset_lock_all_ctx(display->drm, ctx); 49 if (ret != -EDEADLK) 50 break; 51 52 drm_modeset_backoff(ctx); 53 } 54 /* 55 * Disabling the crtcs gracefully seems nicer. Also the 56 * g33 docs say we should at least disable all the planes. 57 */ 58 state = drm_atomic_helper_duplicate_state(display->drm, ctx); 59 if (IS_ERR(state)) { 60 ret = PTR_ERR(state); 61 drm_err(display->drm, "Duplicating state failed with %i\n", 62 ret); 63 return true; 64 } 65 66 ret = drm_atomic_helper_disable_all(display->drm, ctx); 67 if (ret) { 68 drm_err(display->drm, "Suspending crtc's failed with %i\n", 69 ret); 70 drm_atomic_state_put(state); 71 return true; 72 } 73 74 display->restore.modeset_state = state; 75 state->acquire_ctx = ctx; 76 77 return true; 78 } 79 80 void intel_display_reset_finish(struct intel_display *display, bool test_only) 81 { 82 struct drm_i915_private *i915 = to_i915(display->drm); 83 struct drm_modeset_acquire_ctx *ctx = &display->restore.reset_ctx; 84 struct drm_atomic_state *state; 85 int ret; 86 87 if (!HAS_DISPLAY(display)) 88 return; 89 90 state = fetch_and_zero(&display->restore.modeset_state); 91 if (!state) 92 goto unlock; 93 94 /* reset doesn't touch the display */ 95 if (test_only) { 96 /* for testing only restore the display */ 97 ret = drm_atomic_helper_commit_duplicated_state(state, ctx); 98 if (ret) { 99 drm_WARN_ON(display->drm, ret == -EDEADLK); 100 drm_err(display->drm, 101 "Restoring old state failed with %i\n", ret); 102 } 103 } else { 104 /* 105 * The display has been reset as well, 106 * so need a full re-initialization. 107 */ 108 intel_pps_unlock_regs_wa(display); 109 intel_display_driver_init_hw(display); 110 intel_clock_gating_init(i915); 111 intel_cx0_pll_power_save_wa(display); 112 intel_hpd_init(display); 113 114 ret = __intel_display_driver_resume(display, state, ctx); 115 if (ret) 116 drm_err(display->drm, 117 "Restoring old state failed with %i\n", ret); 118 119 intel_hpd_poll_disable(display); 120 } 121 122 drm_atomic_state_put(state); 123 unlock: 124 drm_modeset_drop_locks(ctx); 125 drm_modeset_acquire_fini(ctx); 126 mutex_unlock(&display->drm->mode_config.mutex); 127 } 128