| 1 | /* |
| 2 | * Copyright © 2016 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include "../i915_selftest.h" |
| 26 | |
| 27 | #include "igt_flush_test.h" |
| 28 | #include "mock_gem_device.h" |
| 29 | #include "huge_gem_object.h" |
| 30 | |
| 31 | static int igt_gem_object(void *arg) |
| 32 | { |
| 33 | struct drm_i915_private *i915 = arg; |
| 34 | struct drm_i915_gem_object *obj; |
| 35 | int err = -ENOMEM; |
| 36 | |
| 37 | /* Basic test to ensure we can create an object */ |
| 38 | |
| 39 | obj = i915_gem_object_create_shmem(i915, PAGE_SIZE); |
| 40 | if (IS_ERR(obj)) { |
| 41 | err = PTR_ERR(obj); |
| 42 | pr_err("i915_gem_object_create failed, err=%d\n", err); |
| 43 | goto out; |
| 44 | } |
| 45 | |
| 46 | err = 0; |
| 47 | i915_gem_object_put(obj); |
| 48 | out: |
| 49 | return err; |
| 50 | } |
| 51 | |
| 52 | static int igt_gem_huge(void *arg) |
| 53 | { |
| 54 | const unsigned int nreal = 509; /* just to be awkward */ |
| 55 | struct drm_i915_private *i915 = arg; |
| 56 | struct drm_i915_gem_object *obj; |
| 57 | unsigned int n; |
| 58 | int err; |
| 59 | |
| 60 | /* Basic sanitycheck of our huge fake object allocation */ |
| 61 | |
| 62 | obj = huge_gem_object(i915, |
| 63 | nreal * PAGE_SIZE, |
| 64 | i915->ggtt.vm.total + PAGE_SIZE); |
| 65 | if (IS_ERR(obj)) |
| 66 | return PTR_ERR(obj); |
| 67 | |
| 68 | err = i915_gem_object_pin_pages(obj); |
| 69 | if (err) { |
| 70 | pr_err("Failed to allocate %u pages (%lu total), err=%d\n", |
| 71 | nreal, obj->base.size / PAGE_SIZE, err); |
| 72 | goto out; |
| 73 | } |
| 74 | |
| 75 | for (n = 0; n < obj->base.size / PAGE_SIZE; n++) { |
| 76 | if (i915_gem_object_get_page(obj, n) != |
| 77 | i915_gem_object_get_page(obj, n % nreal)) { |
| 78 | pr_err("Page lookup mismatch at index %u [%u]\n", |
| 79 | n, n % nreal); |
| 80 | err = -EINVAL; |
| 81 | goto out_unpin; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | out_unpin: |
| 86 | i915_gem_object_unpin_pages(obj); |
| 87 | out: |
| 88 | i915_gem_object_put(obj); |
| 89 | return err; |
| 90 | } |
| 91 | |
| 92 | int i915_gem_object_mock_selftests(void) |
| 93 | { |
| 94 | static const struct i915_subtest tests[] = { |
| 95 | SUBTEST(igt_gem_object), |
| 96 | }; |
| 97 | struct drm_i915_private *i915; |
| 98 | int err; |
| 99 | |
| 100 | i915 = mock_gem_device(); |
| 101 | if (!i915) |
| 102 | return -ENOMEM; |
| 103 | |
| 104 | err = i915_subtests(tests, i915); |
| 105 | |
| 106 | drm_dev_put(&i915->drm); |
| 107 | return err; |
| 108 | } |
| 109 | |
| 110 | int i915_gem_object_live_selftests(struct drm_i915_private *i915) |
| 111 | { |
| 112 | static const struct i915_subtest tests[] = { |
| 113 | SUBTEST(igt_gem_huge), |
| 114 | }; |
| 115 | |
| 116 | return i915_subtests(tests, i915); |
| 117 | } |