treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / gpu / drm / i915 / selftests / mock_region.c
blobb2ad41c27e67644db8c8ca20ac69c4eda991f45a
1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright © 2019 Intel Corporation
4 */
6 #include "gem/i915_gem_region.h"
7 #include "intel_memory_region.h"
9 #include "mock_region.h"
11 static const struct drm_i915_gem_object_ops mock_region_obj_ops = {
12 .get_pages = i915_gem_object_get_pages_buddy,
13 .put_pages = i915_gem_object_put_pages_buddy,
14 .release = i915_gem_object_release_memory_region,
17 static struct drm_i915_gem_object *
18 mock_object_create(struct intel_memory_region *mem,
19 resource_size_t size,
20 unsigned int flags)
22 static struct lock_class_key lock_class;
23 struct drm_i915_private *i915 = mem->i915;
24 struct drm_i915_gem_object *obj;
26 if (size > BIT(mem->mm.max_order) * mem->mm.chunk_size)
27 return ERR_PTR(-E2BIG);
29 obj = i915_gem_object_alloc();
30 if (!obj)
31 return ERR_PTR(-ENOMEM);
33 drm_gem_private_object_init(&i915->drm, &obj->base, size);
34 i915_gem_object_init(obj, &mock_region_obj_ops, &lock_class);
36 obj->read_domains = I915_GEM_DOMAIN_CPU | I915_GEM_DOMAIN_GTT;
38 i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE);
40 i915_gem_object_init_memory_region(obj, mem, flags);
42 return obj;
45 static const struct intel_memory_region_ops mock_region_ops = {
46 .init = intel_memory_region_init_buddy,
47 .release = intel_memory_region_release_buddy,
48 .create_object = mock_object_create,
51 struct intel_memory_region *
52 mock_region_create(struct drm_i915_private *i915,
53 resource_size_t start,
54 resource_size_t size,
55 resource_size_t min_page_size,
56 resource_size_t io_start)
58 return intel_memory_region_create(i915, start, size, min_page_size,
59 io_start, &mock_region_ops);