162306a36Sopenharmony_ci/* SPDX-License-Identifier: MIT */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright © 2008-2018 Intel Corporation
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef I915_RESET_H
762306a36Sopenharmony_ci#define I915_RESET_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/compiler.h>
1062306a36Sopenharmony_ci#include <linux/types.h>
1162306a36Sopenharmony_ci#include <linux/srcu.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include "intel_engine_types.h"
1462306a36Sopenharmony_ci#include "intel_reset_types.h"
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_cistruct i915_request;
1762306a36Sopenharmony_cistruct intel_engine_cs;
1862306a36Sopenharmony_cistruct intel_gt;
1962306a36Sopenharmony_cistruct intel_guc;
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_civoid intel_gt_init_reset(struct intel_gt *gt);
2262306a36Sopenharmony_civoid intel_gt_fini_reset(struct intel_gt *gt);
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci__printf(4, 5)
2562306a36Sopenharmony_civoid intel_gt_handle_error(struct intel_gt *gt,
2662306a36Sopenharmony_ci			   intel_engine_mask_t engine_mask,
2762306a36Sopenharmony_ci			   unsigned long flags,
2862306a36Sopenharmony_ci			   const char *fmt, ...);
2962306a36Sopenharmony_ci#define I915_ERROR_CAPTURE BIT(0)
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_civoid intel_gt_reset(struct intel_gt *gt,
3262306a36Sopenharmony_ci		    intel_engine_mask_t stalled_mask,
3362306a36Sopenharmony_ci		    const char *reason);
3462306a36Sopenharmony_ciint intel_engine_reset(struct intel_engine_cs *engine,
3562306a36Sopenharmony_ci		       const char *reason);
3662306a36Sopenharmony_ciint __intel_engine_reset_bh(struct intel_engine_cs *engine,
3762306a36Sopenharmony_ci			    const char *reason);
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_civoid __i915_request_reset(struct i915_request *rq, bool guilty);
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ciint __must_check intel_gt_reset_trylock(struct intel_gt *gt, int *srcu);
4262306a36Sopenharmony_ciint __must_check intel_gt_reset_lock_interruptible(struct intel_gt *gt, int *srcu);
4362306a36Sopenharmony_civoid intel_gt_reset_unlock(struct intel_gt *gt, int tag);
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_civoid intel_gt_set_wedged(struct intel_gt *gt);
4662306a36Sopenharmony_cibool intel_gt_unset_wedged(struct intel_gt *gt);
4762306a36Sopenharmony_ciint intel_gt_terminally_wedged(struct intel_gt *gt);
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci/*
5062306a36Sopenharmony_ci * There's no unset_wedged_on_init paired with this one.
5162306a36Sopenharmony_ci * Once we're wedged on init, there's no going back.
5262306a36Sopenharmony_ci * Same thing for unset_wedged_on_fini.
5362306a36Sopenharmony_ci */
5462306a36Sopenharmony_civoid intel_gt_set_wedged_on_init(struct intel_gt *gt);
5562306a36Sopenharmony_civoid intel_gt_set_wedged_on_fini(struct intel_gt *gt);
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ciint __intel_gt_reset(struct intel_gt *gt, intel_engine_mask_t engine_mask);
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ciint intel_reset_guc(struct intel_gt *gt);
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_cistruct intel_wedge_me {
6262306a36Sopenharmony_ci	struct delayed_work work;
6362306a36Sopenharmony_ci	struct intel_gt *gt;
6462306a36Sopenharmony_ci	const char *name;
6562306a36Sopenharmony_ci};
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_civoid __intel_init_wedge(struct intel_wedge_me *w,
6862306a36Sopenharmony_ci			struct intel_gt *gt,
6962306a36Sopenharmony_ci			long timeout,
7062306a36Sopenharmony_ci			const char *name);
7162306a36Sopenharmony_civoid __intel_fini_wedge(struct intel_wedge_me *w);
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci#define intel_wedge_on_timeout(W, GT, TIMEOUT)				\
7462306a36Sopenharmony_ci	for (__intel_init_wedge((W), (GT), (TIMEOUT), __func__);	\
7562306a36Sopenharmony_ci	     (W)->gt;							\
7662306a36Sopenharmony_ci	     __intel_fini_wedge((W)))
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_cibool intel_has_gpu_reset(const struct intel_gt *gt);
7962306a36Sopenharmony_cibool intel_has_reset_engine(const struct intel_gt *gt);
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#endif /* I915_RESET_H */
82