xref: /linux/drivers/gpu/drm/i915/i915_gem_ww.h (revision 3f0a50f345f78183f6e9b39c2f45ca5dcaa511ca)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2020 Intel Corporation
4  */
5 #ifndef __I915_GEM_WW_H__
6 #define __I915_GEM_WW_H__
7 
8 #include <drm/drm_drv.h>
9 
10 struct i915_gem_ww_ctx {
11 	struct ww_acquire_ctx ctx;
12 	struct list_head obj_list;
13 	struct drm_i915_gem_object *contended;
14 	bool intr;
15 };
16 
17 void i915_gem_ww_ctx_init(struct i915_gem_ww_ctx *ctx, bool intr);
18 void i915_gem_ww_ctx_fini(struct i915_gem_ww_ctx *ctx);
19 int __must_check i915_gem_ww_ctx_backoff(struct i915_gem_ww_ctx *ctx);
20 void i915_gem_ww_unlock_single(struct drm_i915_gem_object *obj);
21 
22 /* Internal function used by the inlines! Don't use. */
23 static inline int __i915_gem_ww_fini(struct i915_gem_ww_ctx *ww, int err)
24 {
25 	if (err == -EDEADLK) {
26 		err = i915_gem_ww_ctx_backoff(ww);
27 		if (!err)
28 			err = -EDEADLK;
29 	}
30 
31 	if (err != -EDEADLK)
32 		i915_gem_ww_ctx_fini(ww);
33 
34 	return err;
35 }
36 
37 #define for_i915_gem_ww(_ww, _err, _intr)			  \
38 	for (i915_gem_ww_ctx_init(_ww, _intr), (_err) = -EDEADLK; \
39 	     (_err) == -EDEADLK;				  \
40 	     (_err) = __i915_gem_ww_fini(_ww, _err))
41 #endif
42