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 struct drm_i915_gem_object *
35 __i915_gem_lmem_object_create(struct intel_memory_region *mem,
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 	struct drm_i915_gem_object *obj;
42 
43 	obj = i915_gem_object_alloc();
44 	if (!obj)
45 		return ERR_PTR(-ENOMEM);
46 
47 	drm_gem_private_object_init(&i915->drm, &obj->base, size);
48 	i915_gem_object_init(obj, &i915_gem_lmem_obj_ops, &lock_class);
49 
50 	obj->read_domains = I915_GEM_DOMAIN_WC | I915_GEM_DOMAIN_GTT;
51 
52 	i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE);
53 
54 	i915_gem_object_init_memory_region(obj, mem, flags);
55 
56 	return obj;
57 }
58