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 	.flags = I915_GEM_OBJECT_HAS_IOMEM,
13 
14 	.get_pages = i915_gem_object_get_pages_buddy,
15 	.put_pages = i915_gem_object_put_pages_buddy,
16 	.release = i915_gem_object_release_memory_region,
17 };
18 
19 bool i915_gem_object_is_lmem(struct drm_i915_gem_object *obj)
20 {
21 	return obj->ops == &i915_gem_lmem_obj_ops;
22 }
23 
24 struct drm_i915_gem_object *
25 i915_gem_object_create_lmem(struct drm_i915_private *i915,
26 			    resource_size_t size,
27 			    unsigned int flags)
28 {
29 	return i915_gem_object_create_region(i915->mm.regions[INTEL_REGION_LMEM],
30 					     size, flags);
31 }
32 
33 struct drm_i915_gem_object *
34 __i915_gem_lmem_object_create(struct intel_memory_region *mem,
35 			      resource_size_t size,
36 			      unsigned int flags)
37 {
38 	static struct lock_class_key lock_class;
39 	struct drm_i915_private *i915 = mem->i915;
40 	struct drm_i915_gem_object *obj;
41 
42 	obj = i915_gem_object_alloc();
43 	if (!obj)
44 		return ERR_PTR(-ENOMEM);
45 
46 	drm_gem_private_object_init(&i915->drm, &obj->base, size);
47 	i915_gem_object_init(obj, &i915_gem_lmem_obj_ops, &lock_class);
48 
49 	obj->read_domains = I915_GEM_DOMAIN_WC | I915_GEM_DOMAIN_GTT;
50 
51 	i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE);
52 
53 	i915_gem_object_init_memory_region(obj, mem, flags);
54 
55 	return obj;
56 }
57