0001
0002
0003
0004
0005
0006 #ifndef __I915_VMA_RESOURCE_H__
0007 #define __I915_VMA_RESOURCE_H__
0008
0009 #include <linux/dma-fence.h>
0010 #include <linux/refcount.h>
0011
0012 #include "i915_gem.h"
0013 #include "i915_scatterlist.h"
0014 #include "i915_sw_fence.h"
0015 #include "intel_runtime_pm.h"
0016
0017 struct intel_memory_region;
0018
0019 struct i915_page_sizes {
0020
0021
0022
0023
0024 unsigned int phys;
0025
0026
0027
0028
0029
0030
0031
0032
0033 unsigned int sg;
0034 };
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 struct i915_vma_resource {
0076 struct dma_fence unbind_fence;
0077
0078 spinlock_t lock;
0079 refcount_t hold_count;
0080 struct work_struct work;
0081 struct i915_sw_fence chain;
0082 struct rb_node rb;
0083 u64 __subtree_last;
0084 struct i915_address_space *vm;
0085 intel_wakeref_t wakeref;
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100 struct i915_vma_bindinfo {
0101 struct sg_table *pages;
0102 struct i915_page_sizes page_sizes;
0103 struct i915_refct_sgt *pages_rsgt;
0104 bool readonly:1;
0105 bool lmem:1;
0106 } bi;
0107
0108 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
0109 struct intel_memory_region *mr;
0110 #endif
0111 const struct i915_vma_ops *ops;
0112 void *private;
0113 u64 start;
0114 u64 node_size;
0115 u64 vma_size;
0116 u32 page_sizes_gtt;
0117
0118 u32 bound_flags;
0119 bool allocated:1;
0120 bool immediate_unbind:1;
0121 bool needs_wakeref:1;
0122 bool skip_pte_rewrite:1;
0123
0124 u32 *tlb;
0125 };
0126
0127 bool i915_vma_resource_hold(struct i915_vma_resource *vma_res,
0128 bool *lockdep_cookie);
0129
0130 void i915_vma_resource_unhold(struct i915_vma_resource *vma_res,
0131 bool lockdep_cookie);
0132
0133 struct i915_vma_resource *i915_vma_resource_alloc(void);
0134
0135 void i915_vma_resource_free(struct i915_vma_resource *vma_res);
0136
0137 struct dma_fence *i915_vma_resource_unbind(struct i915_vma_resource *vma_res,
0138 u32 *tlb);
0139
0140 void __i915_vma_resource_init(struct i915_vma_resource *vma_res);
0141
0142
0143
0144
0145
0146
0147
0148 static inline struct i915_vma_resource
0149 *i915_vma_resource_get(struct i915_vma_resource *vma_res)
0150 {
0151 dma_fence_get(&vma_res->unbind_fence);
0152 return vma_res;
0153 }
0154
0155
0156
0157
0158
0159 static inline void i915_vma_resource_put(struct i915_vma_resource *vma_res)
0160 {
0161 dma_fence_put(&vma_res->unbind_fence);
0162 }
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186 static inline void i915_vma_resource_init(struct i915_vma_resource *vma_res,
0187 struct i915_address_space *vm,
0188 struct sg_table *pages,
0189 const struct i915_page_sizes *page_sizes,
0190 struct i915_refct_sgt *pages_rsgt,
0191 bool readonly,
0192 bool lmem,
0193 struct intel_memory_region *mr,
0194 const struct i915_vma_ops *ops,
0195 void *private,
0196 u64 start,
0197 u64 node_size,
0198 u64 size)
0199 {
0200 __i915_vma_resource_init(vma_res);
0201 vma_res->vm = vm;
0202 vma_res->bi.pages = pages;
0203 vma_res->bi.page_sizes = *page_sizes;
0204 if (pages_rsgt)
0205 vma_res->bi.pages_rsgt = i915_refct_sgt_get(pages_rsgt);
0206 vma_res->bi.readonly = readonly;
0207 vma_res->bi.lmem = lmem;
0208 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
0209 vma_res->mr = mr;
0210 #endif
0211 vma_res->ops = ops;
0212 vma_res->private = private;
0213 vma_res->start = start;
0214 vma_res->node_size = node_size;
0215 vma_res->vma_size = size;
0216 }
0217
0218 static inline void i915_vma_resource_fini(struct i915_vma_resource *vma_res)
0219 {
0220 GEM_BUG_ON(refcount_read(&vma_res->hold_count) != 1);
0221 if (vma_res->bi.pages_rsgt)
0222 i915_refct_sgt_put(vma_res->bi.pages_rsgt);
0223 i915_sw_fence_fini(&vma_res->chain);
0224 }
0225
0226 int i915_vma_resource_bind_dep_sync(struct i915_address_space *vm,
0227 u64 first,
0228 u64 last,
0229 bool intr);
0230
0231 int i915_vma_resource_bind_dep_await(struct i915_address_space *vm,
0232 struct i915_sw_fence *sw_fence,
0233 u64 first,
0234 u64 last,
0235 bool intr,
0236 gfp_t gfp);
0237
0238 void i915_vma_resource_bind_dep_sync_all(struct i915_address_space *vm);
0239
0240 void i915_vma_resource_module_exit(void);
0241
0242 int i915_vma_resource_module_init(void);
0243
0244 #endif