1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2019 Intel Corporation 4 */ 5 6 #include "gem/i915_gem_region.h" 7 #include "intel_memory_region.h" 8 9 #include "mock_region.h" 10 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, 15 }; 16 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) 21 { 22 static struct lock_class_key lock_class; 23 struct drm_i915_private *i915 = mem->i915; 24 struct drm_i915_gem_object *obj; 25 26 if (size > BIT(mem->mm.max_order) * mem->mm.chunk_size) 27 return ERR_PTR(-E2BIG); 28 29 obj = i915_gem_object_alloc(); 30 if (!obj) 31 return ERR_PTR(-ENOMEM); 32 33 drm_gem_private_object_init(&i915->drm, &obj->base, size); 34 i915_gem_object_init(obj, &mock_region_obj_ops, &lock_class); 35 36 obj->read_domains = I915_GEM_DOMAIN_CPU | I915_GEM_DOMAIN_GTT; 37 38 i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE); 39 40 i915_gem_object_init_memory_region(obj, mem, flags); 41 42 return obj; 43 } 44 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, 49 }; 50 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) 57 { 58 return intel_memory_region_create(i915, start, size, min_page_size, 59 io_start, &mock_region_ops); 60 } 61