1 /* $NetBSD: i915_gem_object.c,v 1.2 2021/12/18 23:45:30 riastradh Exp $ */ 2 3 /* 4 * SPDX-License-Identifier: MIT 5 * 6 * Copyright 2016 Intel Corporation 7 */ 8 9 #include <sys/cdefs.h> 10 __KERNEL_RCSID(0, "$NetBSD: i915_gem_object.c,v 1.2 2021/12/18 23:45:30 riastradh Exp $"); 11 12 #include "i915_selftest.h" 13 14 #include "huge_gem_object.h" 15 #include "selftests/igt_flush_test.h" 16 #include "selftests/mock_gem_device.h" 17 18 static int igt_gem_object(void *arg) 19 { 20 struct drm_i915_private *i915 = arg; 21 struct drm_i915_gem_object *obj; 22 int err = -ENOMEM; 23 24 /* Basic test to ensure we can create an object */ 25 26 obj = i915_gem_object_create_shmem(i915, PAGE_SIZE); 27 if (IS_ERR(obj)) { 28 err = PTR_ERR(obj); 29 pr_err("i915_gem_object_create failed, err=%d\n", err); 30 goto out; 31 } 32 33 err = 0; 34 i915_gem_object_put(obj); 35 out: 36 return err; 37 } 38 39 static int igt_gem_huge(void *arg) 40 { 41 const unsigned int nreal = 509; /* just to be awkward */ 42 struct drm_i915_private *i915 = arg; 43 struct drm_i915_gem_object *obj; 44 unsigned int n; 45 int err; 46 47 /* Basic sanitycheck of our huge fake object allocation */ 48 49 obj = huge_gem_object(i915, 50 nreal * PAGE_SIZE, 51 i915->ggtt.vm.total + PAGE_SIZE); 52 if (IS_ERR(obj)) 53 return PTR_ERR(obj); 54 55 err = i915_gem_object_pin_pages(obj); 56 if (err) { 57 pr_err("Failed to allocate %u pages (%lu total), err=%d\n", 58 nreal, obj->base.size / PAGE_SIZE, err); 59 goto out; 60 } 61 62 for (n = 0; n < obj->base.size / PAGE_SIZE; n++) { 63 if (i915_gem_object_get_page(obj, n) != 64 i915_gem_object_get_page(obj, n % nreal)) { 65 pr_err("Page lookup mismatch at index %u [%u]\n", 66 n, n % nreal); 67 err = -EINVAL; 68 goto out_unpin; 69 } 70 } 71 72 out_unpin: 73 i915_gem_object_unpin_pages(obj); 74 out: 75 i915_gem_object_put(obj); 76 return err; 77 } 78 79 int i915_gem_object_mock_selftests(void) 80 { 81 static const struct i915_subtest tests[] = { 82 SUBTEST(igt_gem_object), 83 }; 84 struct drm_i915_private *i915; 85 int err; 86 87 i915 = mock_gem_device(); 88 if (!i915) 89 return -ENOMEM; 90 91 err = i915_subtests(tests, i915); 92 93 drm_dev_put(&i915->drm); 94 return err; 95 } 96 97 int i915_gem_object_live_selftests(struct drm_i915_private *i915) 98 { 99 static const struct i915_subtest tests[] = { 100 SUBTEST(igt_gem_huge), 101 }; 102 103 return i915_subtests(tests, i915); 104 } 105