1 /* $NetBSD: igt_live_test.c,v 1.2 2021/12/18 23:45:31 riastradh Exp $ */
2
3 /*
4 * SPDX-License-Identifier: MIT
5 *
6 * Copyright © 2018 Intel Corporation
7 */
8
9 #include <sys/cdefs.h>
10 __KERNEL_RCSID(0, "$NetBSD: igt_live_test.c,v 1.2 2021/12/18 23:45:31 riastradh Exp $");
11
12 #include "i915_drv.h"
13 #include "gt/intel_gt_requests.h"
14
15 #include "../i915_selftest.h"
16 #include "igt_flush_test.h"
17 #include "igt_live_test.h"
18
igt_live_test_begin(struct igt_live_test * t,struct drm_i915_private * i915,const char * func,const char * name)19 int igt_live_test_begin(struct igt_live_test *t,
20 struct drm_i915_private *i915,
21 const char *func,
22 const char *name)
23 {
24 struct intel_gt *gt = &i915->gt;
25 struct intel_engine_cs *engine;
26 enum intel_engine_id id;
27 int err;
28
29 t->i915 = i915;
30 t->func = func;
31 t->name = name;
32
33 err = intel_gt_wait_for_idle(gt, MAX_SCHEDULE_TIMEOUT);
34 if (err) {
35 pr_err("%s(%s): failed to idle before, with err=%d!",
36 func, name, err);
37 return err;
38 }
39
40 t->reset_global = i915_reset_count(&i915->gpu_error);
41
42 for_each_engine(engine, gt, id)
43 t->reset_engine[id] =
44 i915_reset_engine_count(&i915->gpu_error, engine);
45
46 return 0;
47 }
48
igt_live_test_end(struct igt_live_test * t)49 int igt_live_test_end(struct igt_live_test *t)
50 {
51 struct drm_i915_private *i915 = t->i915;
52 struct intel_engine_cs *engine;
53 enum intel_engine_id id;
54
55 if (igt_flush_test(i915))
56 return -EIO;
57
58 if (t->reset_global != i915_reset_count(&i915->gpu_error)) {
59 pr_err("%s(%s): GPU was reset %d times!\n",
60 t->func, t->name,
61 i915_reset_count(&i915->gpu_error) - t->reset_global);
62 return -EIO;
63 }
64
65 for_each_engine(engine, &i915->gt, id) {
66 if (t->reset_engine[id] ==
67 i915_reset_engine_count(&i915->gpu_error, engine))
68 continue;
69
70 pr_err("%s(%s): engine '%s' was reset %d times!\n",
71 t->func, t->name, engine->name,
72 i915_reset_engine_count(&i915->gpu_error, engine) -
73 t->reset_engine[id]);
74 return -EIO;
75 }
76
77 return 0;
78 }
79