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