18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * SPDX-License-Identifier: MIT
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright © 2018 Intel Corporation
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include "igt_reset.h"
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include "gt/intel_engine.h"
108c2ecf20Sopenharmony_ci#include "gt/intel_gt.h"
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include "../i915_drv.h"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_civoid igt_global_reset_lock(struct intel_gt *gt)
158c2ecf20Sopenharmony_ci{
168c2ecf20Sopenharmony_ci	struct intel_engine_cs *engine;
178c2ecf20Sopenharmony_ci	enum intel_engine_id id;
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci	pr_debug("%s: current gpu_error=%08lx\n", __func__, gt->reset.flags);
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci	while (test_and_set_bit(I915_RESET_BACKOFF, &gt->reset.flags))
228c2ecf20Sopenharmony_ci		wait_event(gt->reset.queue,
238c2ecf20Sopenharmony_ci			   !test_bit(I915_RESET_BACKOFF, &gt->reset.flags));
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	for_each_engine(engine, gt, id) {
268c2ecf20Sopenharmony_ci		while (test_and_set_bit(I915_RESET_ENGINE + id,
278c2ecf20Sopenharmony_ci					&gt->reset.flags))
288c2ecf20Sopenharmony_ci			wait_on_bit(&gt->reset.flags, I915_RESET_ENGINE + id,
298c2ecf20Sopenharmony_ci				    TASK_UNINTERRUPTIBLE);
308c2ecf20Sopenharmony_ci	}
318c2ecf20Sopenharmony_ci}
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_civoid igt_global_reset_unlock(struct intel_gt *gt)
348c2ecf20Sopenharmony_ci{
358c2ecf20Sopenharmony_ci	struct intel_engine_cs *engine;
368c2ecf20Sopenharmony_ci	enum intel_engine_id id;
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	for_each_engine(engine, gt, id)
398c2ecf20Sopenharmony_ci		clear_bit(I915_RESET_ENGINE + id, &gt->reset.flags);
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	clear_bit(I915_RESET_BACKOFF, &gt->reset.flags);
428c2ecf20Sopenharmony_ci	wake_up_all(&gt->reset.queue);
438c2ecf20Sopenharmony_ci}
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cibool igt_force_reset(struct intel_gt *gt)
468c2ecf20Sopenharmony_ci{
478c2ecf20Sopenharmony_ci	intel_gt_set_wedged(gt);
488c2ecf20Sopenharmony_ci	intel_gt_reset(gt, 0, NULL);
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	return !intel_gt_is_wedged(gt);
518c2ecf20Sopenharmony_ci}
52