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 *
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 *
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 #endif
50