Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright © 2016 Intel Corporation
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice (including the next
0012  * paragraph) shall be included in all copies or substantial portions of the
0013  * Software.
0014  *
0015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0018  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0020  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
0021  * IN THE SOFTWARE.
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 }