1 
2 /*
3  * SPDX-License-Identifier: MIT
4  *
5  * Copyright © 2019 Intel Corporation
6  */
7 
8 #include "selftest_llc.h"
9 #include "selftest_rc6.h"
10 #include "selftest_rps.h"
11 
12 static int live_gt_resume(void *arg)
13 {
14 	struct intel_gt *gt = arg;
15 	IGT_TIMEOUT(end_time);
16 	int err;
17 
18 	/* Do several suspend/resume cycles to check we don't explode! */
19 	do {
20 		intel_gt_suspend_prepare(gt);
21 		intel_gt_suspend_late(gt);
22 
23 		if (gt->rc6.enabled) {
24 			pr_err("rc6 still enabled after suspend!\n");
25 			intel_gt_set_wedged_on_init(gt);
26 			err = -EINVAL;
27 			break;
28 		}
29 
30 		err = intel_gt_resume(gt);
31 		if (err)
32 			break;
33 
34 		if (gt->rc6.supported && !gt->rc6.enabled) {
35 			pr_err("rc6 not enabled upon resume!\n");
36 			intel_gt_set_wedged_on_init(gt);
37 			err = -EINVAL;
38 			break;
39 		}
40 
41 		err = st_llc_verify(&gt->llc);
42 		if (err) {
43 			pr_err("llc state not restored upon resume!\n");
44 			intel_gt_set_wedged_on_init(gt);
45 			break;
46 		}
47 	} while (!__igt_timeout(end_time, NULL));
48 
49 	return err;
50 }
51 
52 int intel_gt_pm_live_selftests(struct drm_i915_private *i915)
53 {
54 	static const struct i915_subtest tests[] = {
55 		SUBTEST(live_rc6_manual),
56 		SUBTEST(live_rps_clock_interval),
57 		SUBTEST(live_rps_control),
58 		SUBTEST(live_rps_frequency_cs),
59 		SUBTEST(live_rps_frequency_srm),
60 		SUBTEST(live_rps_power),
61 		SUBTEST(live_rps_interrupt),
62 		SUBTEST(live_rps_dynamic),
63 		SUBTEST(live_gt_resume),
64 	};
65 
66 	if (intel_gt_is_wedged(&i915->gt))
67 		return 0;
68 
69 	return intel_gt_live_subtests(tests, &i915->gt);
70 }
71 
72 int intel_gt_pm_late_selftests(struct drm_i915_private *i915)
73 {
74 	static const struct i915_subtest tests[] = {
75 		/*
76 		 * These tests may leave the system in an undesirable state.
77 		 * They are intended to be run last in CI and the system
78 		 * rebooted afterwards.
79 		 */
80 		SUBTEST(live_rc6_ctx_wa),
81 	};
82 
83 	if (intel_gt_is_wedged(&i915->gt))
84 		return 0;
85 
86 	return intel_gt_live_subtests(tests, &i915->gt);
87 }
88