108 lines · c
1/* SPDX-License-Identifier: MIT */2/*3 * Copyright © 2021 Intel Corporation4 */5#ifndef _I915_GEM_TTM_H_6#define _I915_GEM_TTM_H_7 8#include <drm/ttm/ttm_placement.h>9 10#include "gem/i915_gem_object_types.h"11 12/**13 * i915_gem_to_ttm - Convert a struct drm_i915_gem_object to a14 * struct ttm_buffer_object.15 * @obj: Pointer to the gem object.16 *17 * Return: Pointer to the embedded struct ttm_buffer_object.18 */19static inline struct ttm_buffer_object *20i915_gem_to_ttm(struct drm_i915_gem_object *obj)21{22 return &obj->__do_not_access;23}24 25/*26 * i915 ttm gem object destructor. Internal use only.27 */28void i915_ttm_bo_destroy(struct ttm_buffer_object *bo);29 30/**31 * i915_ttm_is_ghost_object - Check if the ttm bo is a ghost object.32 * @bo: Pointer to the ttm buffer object33 *34 * Return: True if the ttm bo is not a i915 object but a ghost ttm object,35 * False otherwise.36 */37static inline bool i915_ttm_is_ghost_object(struct ttm_buffer_object *bo)38{39 return bo->destroy != i915_ttm_bo_destroy;40}41 42/**43 * i915_ttm_to_gem - Convert a struct ttm_buffer_object to an embedding44 * struct drm_i915_gem_object.45 * @bo: Pointer to the ttm buffer object46 *47 * Return: Pointer to the embedding struct drm_i915_gem_object.48 */49static inline struct drm_i915_gem_object *50i915_ttm_to_gem(struct ttm_buffer_object *bo)51{52 return container_of(bo, struct drm_i915_gem_object, __do_not_access);53}54 55int __i915_gem_ttm_object_init(struct intel_memory_region *mem,56 struct drm_i915_gem_object *obj,57 resource_size_t offset,58 resource_size_t size,59 resource_size_t page_size,60 unsigned int flags);61 62/* Internal I915 TTM declarations and definitions below. */63 64#define I915_PL_LMEM0 TTM_PL_PRIV65#define I915_PL_SYSTEM TTM_PL_SYSTEM66#define I915_PL_STOLEN TTM_PL_VRAM67#define I915_PL_GGTT TTM_PL_TT68 69struct ttm_placement *i915_ttm_sys_placement(void);70 71void i915_ttm_free_cached_io_rsgt(struct drm_i915_gem_object *obj);72 73struct i915_refct_sgt *74i915_ttm_resource_get_st(struct drm_i915_gem_object *obj,75 struct ttm_resource *res);76 77void i915_ttm_adjust_lru(struct drm_i915_gem_object *obj);78 79int i915_ttm_purge(struct drm_i915_gem_object *obj);80 81/**82 * i915_ttm_gtt_binds_lmem - Should the memory be viewed as LMEM by the GTT?83 * @mem: struct ttm_resource representing the memory.84 *85 * Return: true if memory should be viewed as LMEM for GTT binding purposes,86 * false otherwise.87 */88static inline bool i915_ttm_gtt_binds_lmem(struct ttm_resource *mem)89{90 return mem->mem_type != I915_PL_SYSTEM;91}92 93/**94 * i915_ttm_cpu_maps_iomem - Should the memory be viewed as IOMEM by the CPU?95 * @mem: struct ttm_resource representing the memory.96 *97 * Return: true if memory should be viewed as IOMEM for CPU mapping purposes.98 */99static inline bool i915_ttm_cpu_maps_iomem(struct ttm_resource *mem)100{101 /* Once / if we support GGTT, this is also false for cached ttm_tts */102 return mem && mem->mem_type != I915_PL_SYSTEM;103}104 105bool i915_ttm_resource_mappable(struct ttm_resource *res);106 107#endif108