1 /* SPDX-License-Identifier: MIT */
3 * Copyright © 2021 Intel Corporation
5 #ifndef _I915_GEM_TTM_H_
6 #define _I915_GEM_TTM_H_
8 #include <drm/ttm/ttm_placement.h>
10 #include "gem/i915_gem_object_types.h"
13 * i915_gem_to_ttm - Convert a struct drm_i915_gem_object to a
14 * struct ttm_buffer_object.
15 * @obj: Pointer to the gem object.
17 * Return: Pointer to the embedded struct ttm_buffer_object.
19 static inline struct ttm_buffer_object *
20 i915_gem_to_ttm(struct drm_i915_gem_object *obj)
22 return &obj->__do_not_access;
26 * i915 ttm gem object destructor. Internal use only.
28 void i915_ttm_bo_destroy(struct ttm_buffer_object *bo);
31 * i915_ttm_is_ghost_object - Check if the ttm bo is a ghost object.
32 * @bo: Pointer to the ttm buffer object
34 * Return: True if the ttm bo is not a i915 object but a ghost ttm object,
37 static inline bool i915_ttm_is_ghost_object(struct ttm_buffer_object *bo)
39 return bo->destroy != i915_ttm_bo_destroy;
43 * i915_ttm_to_gem - Convert a struct ttm_buffer_object to an embedding
44 * struct drm_i915_gem_object.
45 * @bo: Pointer to the ttm buffer object
47 * Return: Pointer to the embedding struct drm_i915_gem_object.
49 static inline struct drm_i915_gem_object *
50 i915_ttm_to_gem(struct ttm_buffer_object *bo)
52 return container_of(bo, struct drm_i915_gem_object, __do_not_access);
55 int __i915_gem_ttm_object_init(struct intel_memory_region *mem,
56 struct drm_i915_gem_object *obj,
57 resource_size_t offset,
59 resource_size_t page_size,
62 /* Internal I915 TTM declarations and definitions below. */
64 #define I915_PL_LMEM0 TTM_PL_PRIV
65 #define I915_PL_SYSTEM TTM_PL_SYSTEM
66 #define I915_PL_STOLEN TTM_PL_VRAM
67 #define I915_PL_GGTT TTM_PL_TT
69 struct ttm_placement *i915_ttm_sys_placement(void);
71 void i915_ttm_free_cached_io_rsgt(struct drm_i915_gem_object *obj);
73 struct i915_refct_sgt *
74 i915_ttm_resource_get_st(struct drm_i915_gem_object *obj,
75 struct ttm_resource *res);
77 void i915_ttm_adjust_lru(struct drm_i915_gem_object *obj);
79 int i915_ttm_purge(struct drm_i915_gem_object *obj);
82 * i915_ttm_gtt_binds_lmem - Should the memory be viewed as LMEM by the GTT?
83 * @mem: struct ttm_resource representing the memory.
85 * Return: true if memory should be viewed as LMEM for GTT binding purposes,
88 static inline bool i915_ttm_gtt_binds_lmem(struct ttm_resource *mem)
90 return mem->mem_type != I915_PL_SYSTEM;
94 * i915_ttm_cpu_maps_iomem - Should the memory be viewed as IOMEM by the CPU?
95 * @mem: struct ttm_resource representing the memory.
97 * Return: true if memory should be viewed as IOMEM for CPU mapping purposes.
99 static inline bool i915_ttm_cpu_maps_iomem(struct ttm_resource *mem)
101 /* Once / if we support GGTT, this is also false for cached ttm_tts */
102 return mem && mem->mem_type != I915_PL_SYSTEM;
105 bool i915_ttm_resource_mappable(struct ttm_resource *res);