xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/i915/selftests/igt_reset.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: igt_reset.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_reset.c,v 1.2 2021/12/18 23:45:31 riastradh Exp $");
11 
12 #include "igt_reset.h"
13 
14 #include "gt/intel_engine.h"
15 #include "gt/intel_gt.h"
16 
17 #include "../i915_drv.h"
18 
igt_global_reset_lock(struct intel_gt * gt)19 void igt_global_reset_lock(struct intel_gt *gt)
20 {
21 	struct intel_engine_cs *engine;
22 	enum intel_engine_id id;
23 
24 	pr_debug("%s: current gpu_error=%08lx\n", __func__, gt->reset.flags);
25 
26 	while (test_and_set_bit(I915_RESET_BACKOFF, &gt->reset.flags))
27 		wait_event(gt->reset.queue,
28 			   !test_bit(I915_RESET_BACKOFF, &gt->reset.flags));
29 
30 	for_each_engine(engine, gt, id) {
31 		while (test_and_set_bit(I915_RESET_ENGINE + id,
32 					&gt->reset.flags))
33 			wait_on_bit(&gt->reset.flags, I915_RESET_ENGINE + id,
34 				    TASK_UNINTERRUPTIBLE);
35 	}
36 }
37 
igt_global_reset_unlock(struct intel_gt * gt)38 void igt_global_reset_unlock(struct intel_gt *gt)
39 {
40 	struct intel_engine_cs *engine;
41 	enum intel_engine_id id;
42 
43 	for_each_engine(engine, gt, id)
44 		clear_bit(I915_RESET_ENGINE + id, &gt->reset.flags);
45 
46 	clear_bit(I915_RESET_BACKOFF, &gt->reset.flags);
47 	wake_up_all(&gt->reset.queue);
48 }
49 
igt_force_reset(struct intel_gt * gt)50 bool igt_force_reset(struct intel_gt *gt)
51 {
52 	intel_gt_set_wedged(gt);
53 	intel_gt_reset(gt, 0, NULL);
54 
55 	return !intel_gt_is_wedged(gt);
56 }
57