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 10struct i915_gem_ww_ctx { 11 struct ww_acquire_ctx ctx; 12 struct list_head obj_list; 13 struct drm_i915_gem_object *contended; 14 unsigned short intr; 15 unsigned short loop; 16}; 17 18void i915_gem_ww_ctx_init(struct i915_gem_ww_ctx *ctx, bool intr); 19void i915_gem_ww_ctx_fini(struct i915_gem_ww_ctx *ctx); 20int __must_check i915_gem_ww_ctx_backoff(struct i915_gem_ww_ctx *ctx); 21void i915_gem_ww_unlock_single(struct drm_i915_gem_object *obj); 22 23/* Internal functions used by the inlines! Don't use. */ 24static inline int __i915_gem_ww_fini(struct i915_gem_ww_ctx *ww, int err) 25{ 26 ww->loop = 0; 27 if (err == -EDEADLK) { 28 err = i915_gem_ww_ctx_backoff(ww); 29 if (!err) 30 ww->loop = 1; 31 } 32 33 if (!ww->loop) 34 i915_gem_ww_ctx_fini(ww); 35 36 return err; 37} 38 39static inline void 40__i915_gem_ww_init(struct i915_gem_ww_ctx *ww, bool intr) 41{ 42 i915_gem_ww_ctx_init(ww, intr); 43 ww->loop = 1; 44} 45 46#define for_i915_gem_ww(_ww, _err, _intr) \ 47 for (__i915_gem_ww_init(_ww, _intr); (_ww)->loop; \ 48 _err = __i915_gem_ww_fini(_ww, _err)) 49 50#endif 51