xref: /openbmc/linux/drivers/gpu/drm/i915/i915_gem.h (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
1d501b1d2SChris Wilson /*
2d501b1d2SChris Wilson  * Copyright © 2016 Intel Corporation
3d501b1d2SChris Wilson  *
4d501b1d2SChris Wilson  * Permission is hereby granted, free of charge, to any person obtaining a
5d501b1d2SChris Wilson  * copy of this software and associated documentation files (the "Software"),
6d501b1d2SChris Wilson  * to deal in the Software without restriction, including without limitation
7d501b1d2SChris Wilson  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8d501b1d2SChris Wilson  * and/or sell copies of the Software, and to permit persons to whom the
9d501b1d2SChris Wilson  * Software is furnished to do so, subject to the following conditions:
10d501b1d2SChris Wilson  *
11d501b1d2SChris Wilson  * The above copyright notice and this permission notice (including the next
12d501b1d2SChris Wilson  * paragraph) shall be included in all copies or substantial portions of the
13d501b1d2SChris Wilson  * Software.
14d501b1d2SChris Wilson  *
15d501b1d2SChris Wilson  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16d501b1d2SChris Wilson  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17d501b1d2SChris Wilson  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18d501b1d2SChris Wilson  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19d501b1d2SChris Wilson  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20d501b1d2SChris Wilson  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21d501b1d2SChris Wilson  * IN THE SOFTWARE.
22d501b1d2SChris Wilson  *
23d501b1d2SChris Wilson  */
24d501b1d2SChris Wilson 
25d501b1d2SChris Wilson #ifndef __I915_GEM_H__
26d501b1d2SChris Wilson #define __I915_GEM_H__
27d501b1d2SChris Wilson 
2847979480SChris Wilson #include <linux/bug.h>
295fd5cc73SJani Nikula #include <linux/types.h>
3047979480SChris Wilson 
31a09d9a80SJani Nikula #include <drm/drm_drv.h>
32a09d9a80SJani Nikula 
338ad305f1SChris Wilson #include "i915_utils.h"
348ad305f1SChris Wilson 
355fd5cc73SJani Nikula struct drm_file;
365fd5cc73SJani Nikula struct drm_i915_gem_object;
37e4d2006fSChris Wilson struct drm_i915_private;
385fd5cc73SJani Nikula struct i915_gem_ww_ctx;
3947cd3af6SDave Airlie struct i915_gtt_view;
405fd5cc73SJani Nikula struct i915_vma;
415fd5cc73SJani Nikula 
42*0b31a427SJani Nikula #define I915_GEM_GPU_DOMAINS	       \
43*0b31a427SJani Nikula 	(I915_GEM_DOMAIN_RENDER |      \
44*0b31a427SJani Nikula 	 I915_GEM_DOMAIN_SAMPLER |     \
45*0b31a427SJani Nikula 	 I915_GEM_DOMAIN_COMMAND |     \
46*0b31a427SJani Nikula 	 I915_GEM_DOMAIN_INSTRUCTION | \
47*0b31a427SJani Nikula 	 I915_GEM_DOMAIN_VERTEX)
48*0b31a427SJani Nikula 
495fd5cc73SJani Nikula void i915_gem_init_early(struct drm_i915_private *i915);
505fd5cc73SJani Nikula void i915_gem_cleanup_early(struct drm_i915_private *i915);
515fd5cc73SJani Nikula 
525fd5cc73SJani Nikula void i915_gem_drain_freed_objects(struct drm_i915_private *i915);
535fd5cc73SJani Nikula void i915_gem_drain_workqueue(struct drm_i915_private *i915);
545fd5cc73SJani Nikula 
555fd5cc73SJani Nikula struct i915_vma * __must_check
565fd5cc73SJani Nikula i915_gem_object_ggtt_pin_ww(struct drm_i915_gem_object *obj,
575fd5cc73SJani Nikula 			    struct i915_gem_ww_ctx *ww,
5847cd3af6SDave Airlie 			    const struct i915_gtt_view *view,
595fd5cc73SJani Nikula 			    u64 size, u64 alignment, u64 flags);
605fd5cc73SJani Nikula 
615fd5cc73SJani Nikula struct i915_vma * __must_check
625fd5cc73SJani Nikula i915_gem_object_ggtt_pin(struct drm_i915_gem_object *obj,
6347cd3af6SDave Airlie 			 const struct i915_gtt_view *view,
645fd5cc73SJani Nikula 			 u64 size, u64 alignment, u64 flags);
655fd5cc73SJani Nikula 
665fd5cc73SJani Nikula int i915_gem_object_unbind(struct drm_i915_gem_object *obj,
675fd5cc73SJani Nikula 			   unsigned long flags);
685fd5cc73SJani Nikula #define I915_GEM_OBJECT_UNBIND_ACTIVE BIT(0)
695fd5cc73SJani Nikula #define I915_GEM_OBJECT_UNBIND_BARRIER BIT(1)
705fd5cc73SJani Nikula #define I915_GEM_OBJECT_UNBIND_TEST BIT(2)
715fd5cc73SJani Nikula #define I915_GEM_OBJECT_UNBIND_VM_TRYLOCK BIT(3)
725fd5cc73SJani Nikula #define I915_GEM_OBJECT_UNBIND_ASYNC BIT(4)
735fd5cc73SJani Nikula 
745fd5cc73SJani Nikula void i915_gem_runtime_suspend(struct drm_i915_private *i915);
755fd5cc73SJani Nikula 
765fd5cc73SJani Nikula int __must_check i915_gem_init(struct drm_i915_private *i915);
775fd5cc73SJani Nikula void i915_gem_driver_register(struct drm_i915_private *i915);
785fd5cc73SJani Nikula void i915_gem_driver_unregister(struct drm_i915_private *i915);
795fd5cc73SJani Nikula void i915_gem_driver_remove(struct drm_i915_private *i915);
805fd5cc73SJani Nikula void i915_gem_driver_release(struct drm_i915_private *i915);
815fd5cc73SJani Nikula 
825fd5cc73SJani Nikula int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file);
835fd5cc73SJani Nikula 
845fd5cc73SJani Nikula /* FIXME: All of the below belong somewhere else. */
85e4d2006fSChris Wilson 
86d501b1d2SChris Wilson #ifdef CONFIG_DRM_I915_DEBUG_GEM
877f961d79SChris Wilson 
88bdbf43d7SJani Nikula #define GEM_SHOW_DEBUG() drm_debug_enabled(DRM_UT_DRIVER)
897f961d79SChris Wilson 
9003c62d88SChris Wilson #ifdef CONFIG_DRM_I915_DEBUG_GEM_ONCE
9103c62d88SChris Wilson #define __GEM_BUG(cond) BUG()
9203c62d88SChris Wilson #else
9303c62d88SChris Wilson #define __GEM_BUG(cond) \
9403c62d88SChris Wilson 	WARN(1, "%s:%d GEM_BUG_ON(%s)\n", __func__, __LINE__, __stringify(cond))
9503c62d88SChris Wilson #endif
9603c62d88SChris Wilson 
97d5653ec3SMika Kuoppala #define GEM_BUG_ON(condition) do { if (unlikely((condition))) {	\
98c97fb526SChris Wilson 		GEM_TRACE_ERR("%s:%d GEM_BUG_ON(%s)\n", \
99128326a1SChris Wilson 			      __func__, __LINE__, __stringify(condition)); \
1008ad305f1SChris Wilson 		GEM_TRACE_DUMP(); \
10103c62d88SChris Wilson 		__GEM_BUG(condition); \
102d5653ec3SMika Kuoppala 		} \
103d5653ec3SMika Kuoppala 	} while(0)
10417cfde60SMatthew Auld #define GEM_WARN_ON(expr) WARN_ON(expr)
105eca56a35SChris Wilson 
106bbb8a9d7STvrtko Ursulin #define GEM_DEBUG_WARN_ON(expr) GEM_WARN_ON(expr)
107eca56a35SChris Wilson 
108d501b1d2SChris Wilson #else
1097f961d79SChris Wilson 
1107f961d79SChris Wilson #define GEM_SHOW_DEBUG() (0)
1117f961d79SChris Wilson 
1124cfa20c8SMatthew Auld #define GEM_BUG_ON(expr) BUILD_BUG_ON_INVALID(expr)
113bbb8a9d7STvrtko Ursulin #define GEM_WARN_ON(expr) ({ unlikely(!!(expr)); })
114eca56a35SChris Wilson 
115bbb8a9d7STvrtko Ursulin #define GEM_DEBUG_WARN_ON(expr) ({ BUILD_BUG_ON_INVALID(expr); 0; })
116d501b1d2SChris Wilson #endif
117d501b1d2SChris Wilson 
118bccd3b83SChris Wilson #if IS_ENABLED(CONFIG_DRM_I915_TRACE_GEM)
119bccd3b83SChris Wilson #define GEM_TRACE(...) trace_printk(__VA_ARGS__)
120c97fb526SChris Wilson #define GEM_TRACE_ERR(...) do {						\
121c97fb526SChris Wilson 	pr_err(__VA_ARGS__);						\
122c97fb526SChris Wilson 	trace_printk(__VA_ARGS__);					\
123c97fb526SChris Wilson } while (0)
1247a73e671SChris Wilson #define GEM_TRACE_DUMP() \
12565706203SMichał Winiarski 	do { ftrace_dump(DUMP_ALL); __add_taint_for_CI(TAINT_WARN); } while (0)
12609a4c02eSChris Wilson #define GEM_TRACE_DUMP_ON(expr) \
1277a73e671SChris Wilson 	do { if (expr) GEM_TRACE_DUMP(); } while (0)
128bccd3b83SChris Wilson #else
129bccd3b83SChris Wilson #define GEM_TRACE(...) do { } while (0)
130c97fb526SChris Wilson #define GEM_TRACE_ERR(...) do { } while (0)
131629820fcSChris Wilson #define GEM_TRACE_DUMP() do { } while (0)
13209a4c02eSChris Wilson #define GEM_TRACE_DUMP_ON(expr) BUILD_BUG_ON_INVALID(expr)
133bccd3b83SChris Wilson #endif
134bccd3b83SChris Wilson 
1353d606249SChris Wilson #define I915_GEM_IDLE_TIMEOUT (HZ / 5)
1363d606249SChris Wilson 
137d501b1d2SChris Wilson #endif /* __I915_GEM_H__ */
138