Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / i915 / gem / selftests / i915_gem_object.c
blobbf853c40ec65fcee99a86e5d7b8641fd88de13aa
1 /*
2 * SPDX-License-Identifier: MIT
4 * Copyright © 2016 Intel Corporation
5 */
7 #include "i915_selftest.h"
9 #include "huge_gem_object.h"
10 #include "selftests/igt_flush_test.h"
11 #include "selftests/mock_gem_device.h"
13 static int igt_gem_object(void *arg)
15 struct drm_i915_private *i915 = arg;
16 struct drm_i915_gem_object *obj;
17 int err;
19 /* Basic test to ensure we can create an object */
21 obj = i915_gem_object_create_shmem(i915, PAGE_SIZE);
22 if (IS_ERR(obj)) {
23 err = PTR_ERR(obj);
24 pr_err("i915_gem_object_create failed, err=%d\n", err);
25 goto out;
28 err = 0;
29 i915_gem_object_put(obj);
30 out:
31 return err;
34 static int igt_gem_huge(void *arg)
36 const unsigned int nreal = 509; /* just to be awkward */
37 struct drm_i915_private *i915 = arg;
38 struct drm_i915_gem_object *obj;
39 unsigned int n;
40 int err;
42 /* Basic sanitycheck of our huge fake object allocation */
44 obj = huge_gem_object(i915,
45 nreal * PAGE_SIZE,
46 i915->ggtt.vm.total + PAGE_SIZE);
47 if (IS_ERR(obj))
48 return PTR_ERR(obj);
50 err = i915_gem_object_pin_pages(obj);
51 if (err) {
52 pr_err("Failed to allocate %u pages (%lu total), err=%d\n",
53 nreal, obj->base.size / PAGE_SIZE, err);
54 goto out;
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 %u [%u]\n",
61 n, n % nreal);
62 err = -EINVAL;
63 goto out_unpin;
67 out_unpin:
68 i915_gem_object_unpin_pages(obj);
69 out:
70 i915_gem_object_put(obj);
71 return err;
74 int i915_gem_object_mock_selftests(void)
76 static const struct i915_subtest tests[] = {
77 SUBTEST(igt_gem_object),
79 struct drm_i915_private *i915;
80 int err;
82 i915 = mock_gem_device();
83 if (!i915)
84 return -ENOMEM;
86 err = i915_subtests(tests, i915);
88 mock_destroy_device(i915);
89 return err;
92 int i915_gem_object_live_selftests(struct drm_i915_private *i915)
94 static const struct i915_subtest tests[] = {
95 SUBTEST(igt_gem_huge),
98 return i915_subtests(tests, i915);