Home | History | Annotate | Line # | Download | only in selftests
      1  1.1  riastrad /*	$NetBSD: mock_gtt.c,v 1.2 2021/12/18 23:45:31 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright  2016 Intel Corporation
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      8  1.1  riastrad  * to deal in the Software without restriction, including without limitation
      9  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     11  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     12  1.1  riastrad  *
     13  1.1  riastrad  * The above copyright notice and this permission notice (including the next
     14  1.1  riastrad  * paragraph) shall be included in all copies or substantial portions of the
     15  1.1  riastrad  * Software.
     16  1.1  riastrad  *
     17  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     18  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     19  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     20  1.1  riastrad  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     21  1.1  riastrad  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     22  1.1  riastrad  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
     23  1.1  riastrad  * IN THE SOFTWARE.
     24  1.1  riastrad  *
     25  1.1  riastrad  */
     26  1.1  riastrad 
     27  1.1  riastrad #include <sys/cdefs.h>
     28  1.1  riastrad __KERNEL_RCSID(0, "$NetBSD: mock_gtt.c,v 1.2 2021/12/18 23:45:31 riastradh Exp $");
     29  1.1  riastrad 
     30  1.1  riastrad #include "mock_gtt.h"
     31  1.1  riastrad 
     32  1.1  riastrad static void mock_insert_page(struct i915_address_space *vm,
     33  1.1  riastrad 			     dma_addr_t addr,
     34  1.1  riastrad 			     u64 offset,
     35  1.1  riastrad 			     enum i915_cache_level level,
     36  1.1  riastrad 			     u32 flags)
     37  1.1  riastrad {
     38  1.1  riastrad }
     39  1.1  riastrad 
     40  1.1  riastrad static void mock_insert_entries(struct i915_address_space *vm,
     41  1.1  riastrad 				struct i915_vma *vma,
     42  1.1  riastrad 				enum i915_cache_level level, u32 flags)
     43  1.1  riastrad {
     44  1.1  riastrad }
     45  1.1  riastrad 
     46  1.1  riastrad static int mock_bind_ppgtt(struct i915_vma *vma,
     47  1.1  riastrad 			   enum i915_cache_level cache_level,
     48  1.1  riastrad 			   u32 flags)
     49  1.1  riastrad {
     50  1.1  riastrad 	GEM_BUG_ON(flags & I915_VMA_GLOBAL_BIND);
     51  1.1  riastrad 	set_bit(I915_VMA_LOCAL_BIND_BIT, __i915_vma_flags(vma));
     52  1.1  riastrad 	return 0;
     53  1.1  riastrad }
     54  1.1  riastrad 
     55  1.1  riastrad static void mock_unbind_ppgtt(struct i915_vma *vma)
     56  1.1  riastrad {
     57  1.1  riastrad }
     58  1.1  riastrad 
     59  1.1  riastrad static void mock_cleanup(struct i915_address_space *vm)
     60  1.1  riastrad {
     61  1.1  riastrad }
     62  1.1  riastrad 
     63  1.1  riastrad static void mock_clear_range(struct i915_address_space *vm,
     64  1.1  riastrad 			     u64 start, u64 length)
     65  1.1  riastrad {
     66  1.1  riastrad }
     67  1.1  riastrad 
     68  1.1  riastrad struct i915_ppgtt *mock_ppgtt(struct drm_i915_private *i915, const char *name)
     69  1.1  riastrad {
     70  1.1  riastrad 	struct i915_ppgtt *ppgtt;
     71  1.1  riastrad 
     72  1.1  riastrad 	ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL);
     73  1.1  riastrad 	if (!ppgtt)
     74  1.1  riastrad 		return NULL;
     75  1.1  riastrad 
     76  1.1  riastrad 	ppgtt->vm.gt = &i915->gt;
     77  1.1  riastrad 	ppgtt->vm.i915 = i915;
     78  1.1  riastrad 	ppgtt->vm.total = round_down(U64_MAX, PAGE_SIZE);
     79  1.1  riastrad 	ppgtt->vm.file = ERR_PTR(-ENODEV);
     80  1.1  riastrad 
     81  1.1  riastrad 	i915_address_space_init(&ppgtt->vm, VM_CLASS_PPGTT);
     82  1.1  riastrad 
     83  1.1  riastrad 	ppgtt->vm.clear_range = mock_clear_range;
     84  1.1  riastrad 	ppgtt->vm.insert_page = mock_insert_page;
     85  1.1  riastrad 	ppgtt->vm.insert_entries = mock_insert_entries;
     86  1.1  riastrad 	ppgtt->vm.cleanup = mock_cleanup;
     87  1.1  riastrad 
     88  1.1  riastrad 	ppgtt->vm.vma_ops.bind_vma    = mock_bind_ppgtt;
     89  1.1  riastrad 	ppgtt->vm.vma_ops.unbind_vma  = mock_unbind_ppgtt;
     90  1.1  riastrad 	ppgtt->vm.vma_ops.set_pages   = ppgtt_set_pages;
     91  1.1  riastrad 	ppgtt->vm.vma_ops.clear_pages = clear_pages;
     92  1.1  riastrad 
     93  1.1  riastrad 	return ppgtt;
     94  1.1  riastrad }
     95  1.1  riastrad 
     96  1.1  riastrad static int mock_bind_ggtt(struct i915_vma *vma,
     97  1.1  riastrad 			  enum i915_cache_level cache_level,
     98  1.1  riastrad 			  u32 flags)
     99  1.1  riastrad {
    100  1.1  riastrad 	atomic_or(I915_VMA_GLOBAL_BIND | I915_VMA_LOCAL_BIND, &vma->flags);
    101  1.1  riastrad 	return 0;
    102  1.1  riastrad }
    103  1.1  riastrad 
    104  1.1  riastrad static void mock_unbind_ggtt(struct i915_vma *vma)
    105  1.1  riastrad {
    106  1.1  riastrad }
    107  1.1  riastrad 
    108  1.1  riastrad void mock_init_ggtt(struct drm_i915_private *i915, struct i915_ggtt *ggtt)
    109  1.1  riastrad {
    110  1.1  riastrad 	memset(ggtt, 0, sizeof(*ggtt));
    111  1.1  riastrad 
    112  1.1  riastrad 	ggtt->vm.gt = &i915->gt;
    113  1.1  riastrad 	ggtt->vm.i915 = i915;
    114  1.1  riastrad 	ggtt->vm.is_ggtt = true;
    115  1.1  riastrad 
    116  1.1  riastrad 	ggtt->gmadr = (struct resource) DEFINE_RES_MEM(0, 2048 * PAGE_SIZE);
    117  1.1  riastrad 	ggtt->mappable_end = resource_size(&ggtt->gmadr);
    118  1.1  riastrad 	ggtt->vm.total = 4096 * PAGE_SIZE;
    119  1.1  riastrad 
    120  1.1  riastrad 	ggtt->vm.clear_range = mock_clear_range;
    121  1.1  riastrad 	ggtt->vm.insert_page = mock_insert_page;
    122  1.1  riastrad 	ggtt->vm.insert_entries = mock_insert_entries;
    123  1.1  riastrad 	ggtt->vm.cleanup = mock_cleanup;
    124  1.1  riastrad 
    125  1.1  riastrad 	ggtt->vm.vma_ops.bind_vma    = mock_bind_ggtt;
    126  1.1  riastrad 	ggtt->vm.vma_ops.unbind_vma  = mock_unbind_ggtt;
    127  1.1  riastrad 	ggtt->vm.vma_ops.set_pages   = ggtt_set_pages;
    128  1.1  riastrad 	ggtt->vm.vma_ops.clear_pages = clear_pages;
    129  1.1  riastrad 
    130  1.1  riastrad 	i915_address_space_init(&ggtt->vm, VM_CLASS_GGTT);
    131  1.1  riastrad 	i915->gt.ggtt = ggtt;
    132  1.1  riastrad }
    133  1.1  riastrad 
    134  1.1  riastrad void mock_fini_ggtt(struct i915_ggtt *ggtt)
    135  1.1  riastrad {
    136  1.1  riastrad 	i915_address_space_fini(&ggtt->vm);
    137  1.1  riastrad }
    138