1 // SPDX-License-Identifier: MIT
3 * Copyright © 2018 Intel Corporation
6 #include "i915_selftest.h"
7 #include "selftests/igt_reset.h"
8 #include "selftests/igt_atomic.h"
10 static int igt_global_reset(void *arg)
12 struct drm_i915_private *i915 = arg;
13 unsigned int reset_count;
16 /* Check that we can issue a global GPU reset */
18 igt_global_reset_lock(i915);
20 reset_count = i915_reset_count(&i915->gpu_error);
22 i915_reset(i915, ALL_ENGINES, NULL);
24 if (i915_reset_count(&i915->gpu_error) == reset_count) {
25 pr_err("No GPU reset recorded!\n");
29 igt_global_reset_unlock(i915);
31 if (i915_reset_failed(i915))
37 static int igt_wedged_reset(void *arg)
39 struct drm_i915_private *i915 = arg;
40 intel_wakeref_t wakeref;
42 /* Check that we can recover a wedged device with a GPU reset */
44 igt_global_reset_lock(i915);
45 wakeref = intel_runtime_pm_get(&i915->runtime_pm);
47 i915_gem_set_wedged(i915);
49 GEM_BUG_ON(!i915_reset_failed(i915));
50 i915_reset(i915, ALL_ENGINES, NULL);
52 intel_runtime_pm_put(&i915->runtime_pm, wakeref);
53 igt_global_reset_unlock(i915);
55 return i915_reset_failed(i915) ? -EIO : 0;
58 static int igt_atomic_reset(void *arg)
60 struct drm_i915_private *i915 = arg;
61 const typeof(*igt_atomic_phases) *p;
64 /* Check that the resets are usable from atomic context */
66 igt_global_reset_lock(i915);
67 mutex_lock(&i915->drm.struct_mutex);
69 /* Flush any requests before we get started and check basics */
70 if (!igt_force_reset(i915))
73 for (p = igt_atomic_phases; p->name; p++) {
74 GEM_TRACE("intel_gpu_reset under %s\n", p->name);
76 p->critical_section_begin();
78 err = intel_gpu_reset(i915, ALL_ENGINES);
80 p->critical_section_end();
83 pr_err("intel_gpu_reset failed under %s\n", p->name);
88 /* As we poke around the guts, do a full reset before continuing. */
89 igt_force_reset(i915);
92 mutex_unlock(&i915->drm.struct_mutex);
93 igt_global_reset_unlock(i915);
98 int intel_reset_live_selftests(struct drm_i915_private *i915)
100 static const struct i915_subtest tests[] = {
101 SUBTEST(igt_global_reset), /* attempt to recover GPU first */
102 SUBTEST(igt_wedged_reset),
103 SUBTEST(igt_atomic_reset),
105 intel_wakeref_t wakeref;
108 if (!intel_has_gpu_reset(i915))
111 if (i915_terminally_wedged(i915))
112 return -EIO; /* we're long past hope of a successful reset */
114 with_intel_runtime_pm(&i915->runtime_pm, wakeref)
115 err = i915_subtests(tests, i915);