root/drivers/gpu/drm/i915/gem/selftests/i915_gem_phys.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. mock_phys_object
  2. i915_gem_phys_mock_selftests

   1 /*
   2  * SPDX-License-Identifier: MIT
   3  *
   4  * Copyright © 2016 Intel Corporation
   5  */
   6 
   7 #include "i915_selftest.h"
   8 
   9 #include "selftests/mock_gem_device.h"
  10 
  11 static int mock_phys_object(void *arg)
  12 {
  13         struct drm_i915_private *i915 = arg;
  14         struct drm_i915_gem_object *obj;
  15         int err;
  16 
  17         /* Create an object and bind it to a contiguous set of physical pages,
  18          * i.e. exercise the i915_gem_object_phys API.
  19          */
  20 
  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;
  26         }
  27 
  28         mutex_lock(&i915->drm.struct_mutex);
  29         err = i915_gem_object_attach_phys(obj, PAGE_SIZE);
  30         mutex_unlock(&i915->drm.struct_mutex);
  31         if (err) {
  32                 pr_err("i915_gem_object_attach_phys failed, err=%d\n", err);
  33                 goto out_obj;
  34         }
  35 
  36         if (obj->ops != &i915_gem_phys_ops) {
  37                 pr_err("i915_gem_object_attach_phys did not create a phys object\n");
  38                 err = -EINVAL;
  39                 goto out_obj;
  40         }
  41 
  42         if (!atomic_read(&obj->mm.pages_pin_count)) {
  43                 pr_err("i915_gem_object_attach_phys did not pin its phys pages\n");
  44                 err = -EINVAL;
  45                 goto out_obj;
  46         }
  47 
  48         /* Make the object dirty so that put_pages must do copy back the data */
  49         i915_gem_object_lock(obj);
  50         err = i915_gem_object_set_to_gtt_domain(obj, true);
  51         i915_gem_object_unlock(obj);
  52         if (err) {
  53                 pr_err("i915_gem_object_set_to_gtt_domain failed with err=%d\n",
  54                        err);
  55                 goto out_obj;
  56         }
  57 
  58 out_obj:
  59         i915_gem_object_put(obj);
  60 out:
  61         return err;
  62 }
  63 
  64 int i915_gem_phys_mock_selftests(void)
  65 {
  66         static const struct i915_subtest tests[] = {
  67                 SUBTEST(mock_phys_object),
  68         };
  69         struct drm_i915_private *i915;
  70         int err;
  71 
  72         i915 = mock_gem_device();
  73         if (!i915)
  74                 return -ENOMEM;
  75 
  76         err = i915_subtests(tests, i915);
  77 
  78         drm_dev_put(&i915->drm);
  79         return err;
  80 }

/* [<][>][^][v][top][bottom][index][help] */