1 /*
2  * SPDX-License-Identifier: MIT
3  *
4  * Copyright © 2018 Intel Corporation
5  */
6 
7 #include "../i915_drv.h"
8 
9 #include "../i915_selftest.h"
10 #include "igt_flush_test.h"
11 
12 int igt_flush_test(struct drm_i915_private *i915, unsigned int flags)
13 {
14 	int ret = i915_terminally_wedged(i915) ? -EIO : 0;
15 	int repeat = !!(flags & I915_WAIT_LOCKED);
16 
17 	cond_resched();
18 
19 	do {
20 		if (i915_gem_wait_for_idle(i915, flags, HZ / 5) == -ETIME) {
21 			pr_err("%pS timed out, cancelling all further testing.\n",
22 			       __builtin_return_address(0));
23 
24 			GEM_TRACE("%pS timed out.\n",
25 				  __builtin_return_address(0));
26 			GEM_TRACE_DUMP();
27 
28 			i915_gem_set_wedged(i915);
29 			repeat = 0;
30 			ret = -EIO;
31 		}
32 
33 		/* Ensure we also flush after wedging. */
34 		if (flags & I915_WAIT_LOCKED)
35 			i915_retire_requests(i915);
36 	} while (repeat--);
37 
38 	return ret;
39 }
40