WIP FPC-III support
[linux/fpc-iii.git] / drivers / gpu / drm / i915 / gem / selftests / i915_gem_phys.c
blob8cee68c6a6dc81577d01c1c66d68a9d6cb2e98ef
1 /*
2 * SPDX-License-Identifier: MIT
4 * Copyright © 2016 Intel Corporation
5 */
7 #include "i915_selftest.h"
9 #include "selftests/mock_gem_device.h"
11 static int mock_phys_object(void *arg)
13 struct drm_i915_private *i915 = arg;
14 struct drm_i915_gem_object *obj;
15 int err;
17 /* Create an object and bind it to a contiguous set of physical pages,
18 * i.e. exercise the i915_gem_object_phys API.
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 = i915_gem_object_attach_phys(obj, PAGE_SIZE);
29 if (err) {
30 pr_err("i915_gem_object_attach_phys failed, err=%d\n", err);
31 goto out_obj;
34 if (obj->ops != &i915_gem_phys_ops) {
35 pr_err("i915_gem_object_attach_phys did not create a phys object\n");
36 err = -EINVAL;
37 goto out_obj;
40 if (!atomic_read(&obj->mm.pages_pin_count)) {
41 pr_err("i915_gem_object_attach_phys did not pin its phys pages\n");
42 err = -EINVAL;
43 goto out_obj;
46 /* Make the object dirty so that put_pages must do copy back the data */
47 i915_gem_object_lock(obj, NULL);
48 err = i915_gem_object_set_to_gtt_domain(obj, true);
49 i915_gem_object_unlock(obj);
50 if (err) {
51 pr_err("i915_gem_object_set_to_gtt_domain failed with err=%d\n",
52 err);
53 goto out_obj;
56 out_obj:
57 i915_gem_object_put(obj);
58 out:
59 return err;
62 int i915_gem_phys_mock_selftests(void)
64 static const struct i915_subtest tests[] = {
65 SUBTEST(mock_phys_object),
67 struct drm_i915_private *i915;
68 int err;
70 i915 = mock_gem_device();
71 if (!i915)
72 return -ENOMEM;
74 err = i915_subtests(tests, i915);
76 mock_destroy_device(i915);
77 return err;