1 /* $NetBSD: i915_gem_phys.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_phys.c,v 1.2 2021/12/18 23:45:30 riastradh Exp $");
11
12 #include "i915_selftest.h"
13
14 #include "selftests/mock_gem_device.h"
15
mock_phys_object(void * arg)16 static int mock_phys_object(void *arg)
17 {
18 struct drm_i915_private *i915 = arg;
19 struct drm_i915_gem_object *obj;
20 int err;
21
22 /* Create an object and bind it to a contiguous set of physical pages,
23 * i.e. exercise the i915_gem_object_phys API.
24 */
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 = i915_gem_object_attach_phys(obj, PAGE_SIZE);
34 if (err) {
35 pr_err("i915_gem_object_attach_phys failed, err=%d\n", err);
36 goto out_obj;
37 }
38
39 if (obj->ops != &i915_gem_phys_ops) {
40 pr_err("i915_gem_object_attach_phys did not create a phys object\n");
41 err = -EINVAL;
42 goto out_obj;
43 }
44
45 if (!atomic_read(&obj->mm.pages_pin_count)) {
46 pr_err("i915_gem_object_attach_phys did not pin its phys pages\n");
47 err = -EINVAL;
48 goto out_obj;
49 }
50
51 /* Make the object dirty so that put_pages must do copy back the data */
52 i915_gem_object_lock(obj);
53 err = i915_gem_object_set_to_gtt_domain(obj, true);
54 i915_gem_object_unlock(obj);
55 if (err) {
56 pr_err("i915_gem_object_set_to_gtt_domain failed with err=%d\n",
57 err);
58 goto out_obj;
59 }
60
61 out_obj:
62 i915_gem_object_put(obj);
63 out:
64 return err;
65 }
66
i915_gem_phys_mock_selftests(void)67 int i915_gem_phys_mock_selftests(void)
68 {
69 static const struct i915_subtest tests[] = {
70 SUBTEST(mock_phys_object),
71 };
72 struct drm_i915_private *i915;
73 int err;
74
75 i915 = mock_gem_device();
76 if (!i915)
77 return -ENOMEM;
78
79 err = i915_subtests(tests, i915);
80
81 drm_dev_put(&i915->drm);
82 return err;
83 }
84