Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: MIT */
0002 /*
0003  * Copyright © 2021 Intel Corporation
0004  */
0005 #ifndef _I915_GEM_TTM_H_
0006 #define _I915_GEM_TTM_H_
0007 
0008 #include <drm/ttm/ttm_placement.h>
0009 
0010 #include "gem/i915_gem_object_types.h"
0011 
0012 /**
0013  * i915_gem_to_ttm - Convert a struct drm_i915_gem_object to a
0014  * struct ttm_buffer_object.
0015  * @obj: Pointer to the gem object.
0016  *
0017  * Return: Pointer to the embedded struct ttm_buffer_object.
0018  */
0019 static inline struct ttm_buffer_object *
0020 i915_gem_to_ttm(struct drm_i915_gem_object *obj)
0021 {
0022     return &obj->__do_not_access;
0023 }
0024 
0025 /*
0026  * i915 ttm gem object destructor. Internal use only.
0027  */
0028 void i915_ttm_bo_destroy(struct ttm_buffer_object *bo);
0029 
0030 /**
0031  * i915_ttm_to_gem - Convert a struct ttm_buffer_object to an embedding
0032  * struct drm_i915_gem_object.
0033  *
0034  * Return: Pointer to the embedding struct ttm_buffer_object, or NULL
0035  * if the object was not an i915 ttm object.
0036  */
0037 static inline struct drm_i915_gem_object *
0038 i915_ttm_to_gem(struct ttm_buffer_object *bo)
0039 {
0040     if (bo->destroy != i915_ttm_bo_destroy)
0041         return NULL;
0042 
0043     return container_of(bo, struct drm_i915_gem_object, __do_not_access);
0044 }
0045 
0046 int __i915_gem_ttm_object_init(struct intel_memory_region *mem,
0047                    struct drm_i915_gem_object *obj,
0048                    resource_size_t offset,
0049                    resource_size_t size,
0050                    resource_size_t page_size,
0051                    unsigned int flags);
0052 
0053 /* Internal I915 TTM declarations and definitions below. */
0054 
0055 #define I915_PL_LMEM0 TTM_PL_PRIV
0056 #define I915_PL_SYSTEM TTM_PL_SYSTEM
0057 #define I915_PL_STOLEN TTM_PL_VRAM
0058 #define I915_PL_GGTT TTM_PL_TT
0059 
0060 struct ttm_placement *i915_ttm_sys_placement(void);
0061 
0062 void i915_ttm_free_cached_io_rsgt(struct drm_i915_gem_object *obj);
0063 
0064 struct i915_refct_sgt *
0065 i915_ttm_resource_get_st(struct drm_i915_gem_object *obj,
0066              struct ttm_resource *res);
0067 
0068 void i915_ttm_adjust_lru(struct drm_i915_gem_object *obj);
0069 
0070 int i915_ttm_purge(struct drm_i915_gem_object *obj);
0071 
0072 /**
0073  * i915_ttm_gtt_binds_lmem - Should the memory be viewed as LMEM by the GTT?
0074  * @mem: struct ttm_resource representing the memory.
0075  *
0076  * Return: true if memory should be viewed as LMEM for GTT binding purposes,
0077  * false otherwise.
0078  */
0079 static inline bool i915_ttm_gtt_binds_lmem(struct ttm_resource *mem)
0080 {
0081     return mem->mem_type != I915_PL_SYSTEM;
0082 }
0083 
0084 /**
0085  * i915_ttm_cpu_maps_iomem - Should the memory be viewed as IOMEM by the CPU?
0086  * @mem: struct ttm_resource representing the memory.
0087  *
0088  * Return: true if memory should be viewed as IOMEM for CPU mapping purposes.
0089  */
0090 static inline bool i915_ttm_cpu_maps_iomem(struct ttm_resource *mem)
0091 {
0092     /* Once / if we support GGTT, this is also false for cached ttm_tts */
0093     return mem->mem_type != I915_PL_SYSTEM;
0094 }
0095 
0096 bool i915_ttm_resource_mappable(struct ttm_resource *res);
0097 
0098 #endif