0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 #include "mock_gtt.h"
0026
0027 static void mock_insert_page(struct i915_address_space *vm,
0028 dma_addr_t addr,
0029 u64 offset,
0030 enum i915_cache_level level,
0031 u32 flags)
0032 {
0033 }
0034
0035 static void mock_insert_entries(struct i915_address_space *vm,
0036 struct i915_vma_resource *vma_res,
0037 enum i915_cache_level level, u32 flags)
0038 {
0039 }
0040
0041 static void mock_bind_ppgtt(struct i915_address_space *vm,
0042 struct i915_vm_pt_stash *stash,
0043 struct i915_vma_resource *vma_res,
0044 enum i915_cache_level cache_level,
0045 u32 flags)
0046 {
0047 GEM_BUG_ON(flags & I915_VMA_GLOBAL_BIND);
0048 vma_res->bound_flags |= flags;
0049 }
0050
0051 static void mock_unbind_ppgtt(struct i915_address_space *vm,
0052 struct i915_vma_resource *vma_res)
0053 {
0054 }
0055
0056 static void mock_cleanup(struct i915_address_space *vm)
0057 {
0058 }
0059
0060 static void mock_clear_range(struct i915_address_space *vm,
0061 u64 start, u64 length)
0062 {
0063 }
0064
0065 struct i915_ppgtt *mock_ppgtt(struct drm_i915_private *i915, const char *name)
0066 {
0067 struct i915_ppgtt *ppgtt;
0068
0069 ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL);
0070 if (!ppgtt)
0071 return NULL;
0072
0073 ppgtt->vm.gt = to_gt(i915);
0074 ppgtt->vm.i915 = i915;
0075 ppgtt->vm.total = round_down(U64_MAX, PAGE_SIZE);
0076 ppgtt->vm.dma = i915->drm.dev;
0077
0078 i915_address_space_init(&ppgtt->vm, VM_CLASS_PPGTT);
0079
0080 ppgtt->vm.alloc_pt_dma = alloc_pt_dma;
0081 ppgtt->vm.alloc_scratch_dma = alloc_pt_dma;
0082
0083 ppgtt->vm.clear_range = mock_clear_range;
0084 ppgtt->vm.insert_page = mock_insert_page;
0085 ppgtt->vm.insert_entries = mock_insert_entries;
0086 ppgtt->vm.cleanup = mock_cleanup;
0087
0088 ppgtt->vm.vma_ops.bind_vma = mock_bind_ppgtt;
0089 ppgtt->vm.vma_ops.unbind_vma = mock_unbind_ppgtt;
0090
0091 return ppgtt;
0092 }
0093
0094 static void mock_bind_ggtt(struct i915_address_space *vm,
0095 struct i915_vm_pt_stash *stash,
0096 struct i915_vma_resource *vma_res,
0097 enum i915_cache_level cache_level,
0098 u32 flags)
0099 {
0100 }
0101
0102 static void mock_unbind_ggtt(struct i915_address_space *vm,
0103 struct i915_vma_resource *vma_res)
0104 {
0105 }
0106
0107 void mock_init_ggtt(struct intel_gt *gt)
0108 {
0109 struct i915_ggtt *ggtt = gt->ggtt;
0110
0111 ggtt->vm.gt = gt;
0112 ggtt->vm.i915 = gt->i915;
0113 ggtt->vm.is_ggtt = true;
0114
0115 ggtt->gmadr = (struct resource) DEFINE_RES_MEM(0, 2048 * PAGE_SIZE);
0116 ggtt->mappable_end = resource_size(&ggtt->gmadr);
0117 ggtt->vm.total = 4096 * PAGE_SIZE;
0118
0119 ggtt->vm.alloc_pt_dma = alloc_pt_dma;
0120 ggtt->vm.alloc_scratch_dma = alloc_pt_dma;
0121
0122 ggtt->vm.clear_range = mock_clear_range;
0123 ggtt->vm.insert_page = mock_insert_page;
0124 ggtt->vm.insert_entries = mock_insert_entries;
0125 ggtt->vm.cleanup = mock_cleanup;
0126
0127 ggtt->vm.vma_ops.bind_vma = mock_bind_ggtt;
0128 ggtt->vm.vma_ops.unbind_vma = mock_unbind_ggtt;
0129
0130 i915_address_space_init(&ggtt->vm, VM_CLASS_GGTT);
0131 }
0132
0133 void mock_fini_ggtt(struct i915_ggtt *ggtt)
0134 {
0135 i915_address_space_fini(&ggtt->vm);
0136 }