1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2021 Intel Corporation
4  */
5 #ifndef _I915_GEM_TTM_H_
6 #define _I915_GEM_TTM_H_
7 
8 #include "gem/i915_gem_object_types.h"
9 
10 /**
11  * i915_gem_to_ttm - Convert a struct drm_i915_gem_object to a
12  * struct ttm_buffer_object.
13  * @obj: Pointer to the gem object.
14  *
15  * Return: Pointer to the embedded struct ttm_buffer_object.
16  */
17 static inline struct ttm_buffer_object *
i915_gem_to_ttm(struct drm_i915_gem_object * obj)18 i915_gem_to_ttm(struct drm_i915_gem_object *obj)
19 {
20 	return &obj->__do_not_access;
21 }
22 
23 /*
24  * i915 ttm gem object destructor. Internal use only.
25  */
26 void i915_ttm_bo_destroy(struct ttm_buffer_object *bo);
27 
28 /**
29  * i915_ttm_to_gem - Convert a struct ttm_buffer_object to an embedding
30  * struct drm_i915_gem_object.
31  *
32  * Return: Pointer to the embedding struct ttm_buffer_object, or NULL
33  * if the object was not an i915 ttm object.
34  */
35 static inline struct drm_i915_gem_object *
i915_ttm_to_gem(struct ttm_buffer_object * bo)36 i915_ttm_to_gem(struct ttm_buffer_object *bo)
37 {
38 	if (GEM_WARN_ON(bo->destroy != i915_ttm_bo_destroy))
39 		return NULL;
40 
41 	return container_of(bo, struct drm_i915_gem_object, __do_not_access);
42 }
43 
44 int __i915_gem_ttm_object_init(struct intel_memory_region *mem,
45 			       struct drm_i915_gem_object *obj,
46 			       resource_size_t size,
47 			       resource_size_t page_size,
48 			       unsigned int flags);
49 
50 int i915_gem_obj_copy_ttm(struct drm_i915_gem_object *dst,
51 			  struct drm_i915_gem_object *src,
52 			  bool allow_accel, bool intr);
53 
54 /* Internal I915 TTM declarations and definitions below. */
55 
56 #define I915_PL_LMEM0 TTM_PL_PRIV
57 #define I915_PL_SYSTEM TTM_PL_SYSTEM
58 #define I915_PL_STOLEN TTM_PL_VRAM
59 #define I915_PL_GGTT TTM_PL_TT
60 
61 struct ttm_placement *i915_ttm_sys_placement(void);
62 
63 #endif
64