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

source code of linux/drivers/gpu/drm/i915/gem/selftests/i915_gem_object.c