162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright © 2016 Intel Corporation
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
562306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
662306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation
762306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
862306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
962306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
1062306a36Sopenharmony_ci *
1162306a36Sopenharmony_ci * The above copyright notice and this permission notice (including the next
1262306a36Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
1362306a36Sopenharmony_ci * Software.
1462306a36Sopenharmony_ci *
1562306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1662306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1762306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1862306a36Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1962306a36Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2062306a36Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2162306a36Sopenharmony_ci * IN THE SOFTWARE.
2262306a36Sopenharmony_ci *
2362306a36Sopenharmony_ci */
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci#ifndef __I915_GEM_H__
2662306a36Sopenharmony_ci#define __I915_GEM_H__
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci#include <linux/bug.h>
2962306a36Sopenharmony_ci#include <linux/types.h>
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci#include <drm/drm_drv.h>
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#include "i915_utils.h"
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_cistruct drm_file;
3662306a36Sopenharmony_cistruct drm_i915_gem_object;
3762306a36Sopenharmony_cistruct drm_i915_private;
3862306a36Sopenharmony_cistruct i915_gem_ww_ctx;
3962306a36Sopenharmony_cistruct i915_gtt_view;
4062306a36Sopenharmony_cistruct i915_vma;
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#define I915_GEM_GPU_DOMAINS	       \
4362306a36Sopenharmony_ci	(I915_GEM_DOMAIN_RENDER |      \
4462306a36Sopenharmony_ci	 I915_GEM_DOMAIN_SAMPLER |     \
4562306a36Sopenharmony_ci	 I915_GEM_DOMAIN_COMMAND |     \
4662306a36Sopenharmony_ci	 I915_GEM_DOMAIN_INSTRUCTION | \
4762306a36Sopenharmony_ci	 I915_GEM_DOMAIN_VERTEX)
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_civoid i915_gem_init_early(struct drm_i915_private *i915);
5062306a36Sopenharmony_civoid i915_gem_cleanup_early(struct drm_i915_private *i915);
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_civoid i915_gem_drain_freed_objects(struct drm_i915_private *i915);
5362306a36Sopenharmony_civoid i915_gem_drain_workqueue(struct drm_i915_private *i915);
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_cistruct i915_vma * __must_check
5662306a36Sopenharmony_cii915_gem_object_ggtt_pin_ww(struct drm_i915_gem_object *obj,
5762306a36Sopenharmony_ci			    struct i915_gem_ww_ctx *ww,
5862306a36Sopenharmony_ci			    const struct i915_gtt_view *view,
5962306a36Sopenharmony_ci			    u64 size, u64 alignment, u64 flags);
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_cistruct i915_vma * __must_check
6262306a36Sopenharmony_cii915_gem_object_ggtt_pin(struct drm_i915_gem_object *obj,
6362306a36Sopenharmony_ci			 const struct i915_gtt_view *view,
6462306a36Sopenharmony_ci			 u64 size, u64 alignment, u64 flags);
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ciint i915_gem_object_unbind(struct drm_i915_gem_object *obj,
6762306a36Sopenharmony_ci			   unsigned long flags);
6862306a36Sopenharmony_ci#define I915_GEM_OBJECT_UNBIND_ACTIVE BIT(0)
6962306a36Sopenharmony_ci#define I915_GEM_OBJECT_UNBIND_BARRIER BIT(1)
7062306a36Sopenharmony_ci#define I915_GEM_OBJECT_UNBIND_TEST BIT(2)
7162306a36Sopenharmony_ci#define I915_GEM_OBJECT_UNBIND_VM_TRYLOCK BIT(3)
7262306a36Sopenharmony_ci#define I915_GEM_OBJECT_UNBIND_ASYNC BIT(4)
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_civoid i915_gem_runtime_suspend(struct drm_i915_private *i915);
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ciint __must_check i915_gem_init(struct drm_i915_private *i915);
7762306a36Sopenharmony_civoid i915_gem_driver_register(struct drm_i915_private *i915);
7862306a36Sopenharmony_civoid i915_gem_driver_unregister(struct drm_i915_private *i915);
7962306a36Sopenharmony_civoid i915_gem_driver_remove(struct drm_i915_private *i915);
8062306a36Sopenharmony_civoid i915_gem_driver_release(struct drm_i915_private *i915);
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ciint i915_gem_open(struct drm_i915_private *i915, struct drm_file *file);
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci/* FIXME: All of the below belong somewhere else. */
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci#ifdef CONFIG_DRM_I915_DEBUG_GEM
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci#define GEM_SHOW_DEBUG() drm_debug_enabled(DRM_UT_DRIVER)
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci#ifdef CONFIG_DRM_I915_DEBUG_GEM_ONCE
9162306a36Sopenharmony_ci#define __GEM_BUG(cond) BUG()
9262306a36Sopenharmony_ci#else
9362306a36Sopenharmony_ci#define __GEM_BUG(cond) \
9462306a36Sopenharmony_ci	WARN(1, "%s:%d GEM_BUG_ON(%s)\n", __func__, __LINE__, __stringify(cond))
9562306a36Sopenharmony_ci#endif
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci#define GEM_BUG_ON(condition) do { if (unlikely((condition))) {	\
9862306a36Sopenharmony_ci		GEM_TRACE_ERR("%s:%d GEM_BUG_ON(%s)\n", \
9962306a36Sopenharmony_ci			      __func__, __LINE__, __stringify(condition)); \
10062306a36Sopenharmony_ci		GEM_TRACE_DUMP(); \
10162306a36Sopenharmony_ci		__GEM_BUG(condition); \
10262306a36Sopenharmony_ci		} \
10362306a36Sopenharmony_ci	} while(0)
10462306a36Sopenharmony_ci#define GEM_WARN_ON(expr) WARN_ON(expr)
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci#define GEM_DEBUG_WARN_ON(expr) GEM_WARN_ON(expr)
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci#else
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci#define GEM_SHOW_DEBUG() (0)
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci#define GEM_BUG_ON(expr) BUILD_BUG_ON_INVALID(expr)
11362306a36Sopenharmony_ci#define GEM_WARN_ON(expr) ({ unlikely(!!(expr)); })
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci#define GEM_DEBUG_WARN_ON(expr) ({ BUILD_BUG_ON_INVALID(expr); 0; })
11662306a36Sopenharmony_ci#endif
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_I915_TRACE_GEM)
11962306a36Sopenharmony_ci#define GEM_TRACE(...) trace_printk(__VA_ARGS__)
12062306a36Sopenharmony_ci#define GEM_TRACE_ERR(...) do {						\
12162306a36Sopenharmony_ci	pr_err(__VA_ARGS__);						\
12262306a36Sopenharmony_ci	trace_printk(__VA_ARGS__);					\
12362306a36Sopenharmony_ci} while (0)
12462306a36Sopenharmony_ci#define GEM_TRACE_DUMP() \
12562306a36Sopenharmony_ci	do { ftrace_dump(DUMP_ALL); __add_taint_for_CI(TAINT_WARN); } while (0)
12662306a36Sopenharmony_ci#define GEM_TRACE_DUMP_ON(expr) \
12762306a36Sopenharmony_ci	do { if (expr) GEM_TRACE_DUMP(); } while (0)
12862306a36Sopenharmony_ci#else
12962306a36Sopenharmony_ci#define GEM_TRACE(...) do { } while (0)
13062306a36Sopenharmony_ci#define GEM_TRACE_ERR(...) do { } while (0)
13162306a36Sopenharmony_ci#define GEM_TRACE_DUMP() do { } while (0)
13262306a36Sopenharmony_ci#define GEM_TRACE_DUMP_ON(expr) BUILD_BUG_ON_INVALID(expr)
13362306a36Sopenharmony_ci#endif
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci#define I915_GEM_IDLE_TIMEOUT (HZ / 5)
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci#endif /* __I915_GEM_H__ */
138