1/* $NetBSD: mock_region.c,v 1.2 2021/12/18 23:45:31 riastradh Exp $ */ 2 3// SPDX-License-Identifier: MIT 4/* 5 * Copyright �� 2019 Intel Corporation 6 */ 7 8#include <sys/cdefs.h> 9__KERNEL_RCSID(0, "$NetBSD: mock_region.c,v 1.2 2021/12/18 23:45:31 riastradh Exp $"); 10 11#include "gem/i915_gem_region.h" 12#include "intel_memory_region.h" 13 14#include "mock_region.h" 15 16static const struct drm_i915_gem_object_ops mock_region_obj_ops = { 17 .get_pages = i915_gem_object_get_pages_buddy, 18 .put_pages = i915_gem_object_put_pages_buddy, 19 .release = i915_gem_object_release_memory_region, 20}; 21 22static struct drm_i915_gem_object * 23mock_object_create(struct intel_memory_region *mem, 24 resource_size_t size, 25 unsigned int flags) 26{ 27 static struct lock_class_key lock_class; 28 struct drm_i915_private *i915 = mem->i915; 29 struct drm_i915_gem_object *obj; 30 31 if (size > BIT(mem->mm.max_order) * mem->mm.chunk_size) 32 return ERR_PTR(-E2BIG); 33 34 obj = i915_gem_object_alloc(); 35 if (!obj) 36 return ERR_PTR(-ENOMEM); 37 38 drm_gem_private_object_init(&i915->drm, &obj->base, size); 39 i915_gem_object_init(obj, &mock_region_obj_ops, &lock_class); 40 41 obj->read_domains = I915_GEM_DOMAIN_CPU | I915_GEM_DOMAIN_GTT; 42 43 i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE); 44 45 i915_gem_object_init_memory_region(obj, mem, flags); 46 47 return obj; 48} 49 50static const struct intel_memory_region_ops mock_region_ops = { 51 .init = intel_memory_region_init_buddy, 52 .release = intel_memory_region_release_buddy, 53 .create_object = mock_object_create, 54}; 55 56struct intel_memory_region * 57mock_region_create(struct drm_i915_private *i915, 58 resource_size_t start, 59 resource_size_t size, 60 resource_size_t min_page_size, 61 resource_size_t io_start) 62{ 63 return intel_memory_region_create(i915, start, size, min_page_size, 64 io_start, &mock_region_ops); 65} 66