1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2019 Intel Corporation
4  */
5 
6 #include "intel_memory_region.h"
7 #include "gem/i915_gem_region.h"
8 #include "gem/i915_gem_lmem.h"
9 #include "i915_drv.h"
10 
11 const struct drm_i915_gem_object_ops i915_gem_lmem_obj_ops = {
12 	.name = "i915_gem_object_lmem",
13 	.flags = I915_GEM_OBJECT_HAS_IOMEM,
14 
15 	.get_pages = i915_gem_object_get_pages_buddy,
16 	.put_pages = i915_gem_object_put_pages_buddy,
17 	.release = i915_gem_object_release_memory_region,
18 };
19 
20 bool i915_gem_object_is_lmem(struct drm_i915_gem_object *obj)
21 {
22 	return obj->ops == &i915_gem_lmem_obj_ops;
23 }
24 
25 struct drm_i915_gem_object *
26 i915_gem_object_create_lmem(struct drm_i915_private *i915,
27 			    resource_size_t size,
28 			    unsigned int flags)
29 {
30 	return i915_gem_object_create_region(i915->mm.regions[INTEL_REGION_LMEM],
31 					     size, flags);
32 }
33 
34 int __i915_gem_lmem_object_init(struct intel_memory_region *mem,
35 				struct drm_i915_gem_object *obj,
36 				resource_size_t size,
37 				unsigned int flags)
38 {
39 	static struct lock_class_key lock_class;
40 	struct drm_i915_private *i915 = mem->i915;
41 
42 	drm_gem_private_object_init(&i915->drm, &obj->base, size);
43 	i915_gem_object_init(obj, &i915_gem_lmem_obj_ops, &lock_class, flags);
44 
45 	obj->read_domains = I915_GEM_DOMAIN_WC | I915_GEM_DOMAIN_GTT;
46 
47 	i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE);
48 
49 	i915_gem_object_init_memory_region(obj, mem);
50 
51 	return 0;
52 }
53