drm/i915/display: Migrate objects to LMEM if possible for display
[linux-2.6-microblaze.git] / drivers / gpu / drm / i915 / gem / i915_gem_lmem.c
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 void __iomem *
12 i915_gem_object_lmem_io_map(struct drm_i915_gem_object *obj,
13                             unsigned long n,
14                             unsigned long size)
15 {
16         resource_size_t offset;
17
18         GEM_BUG_ON(!i915_gem_object_is_contiguous(obj));
19
20         offset = i915_gem_object_get_dma_address(obj, n);
21         offset -= obj->mm.region->region.start;
22
23         return io_mapping_map_wc(&obj->mm.region->iomap, offset, size);
24 }
25
26 /**
27  * i915_gem_object_is_lmem - Whether the object is resident in
28  * lmem
29  * @obj: The object to check.
30  *
31  * Even if an object is allowed to migrate and change memory region,
32  * this function checks whether it will always be present in lmem when
33  * valid *or* if that's not the case, whether it's currently resident in lmem.
34  * For migratable and evictable objects, the latter only makes sense when
35  * the object is locked.
36  *
37  * Return: Whether the object migratable but resident in lmem, or not
38  * migratable and will be present in lmem when valid.
39  */
40 bool i915_gem_object_is_lmem(struct drm_i915_gem_object *obj)
41 {
42         struct intel_memory_region *mr = READ_ONCE(obj->mm.region);
43
44 #ifdef CONFIG_LOCKDEP
45         if (i915_gem_object_migratable(obj) &&
46             i915_gem_object_evictable(obj))
47                 assert_object_held(obj);
48 #endif
49         return mr && (mr->type == INTEL_MEMORY_LOCAL ||
50                       mr->type == INTEL_MEMORY_STOLEN_LOCAL);
51 }
52
53 /**
54  * __i915_gem_object_is_lmem - Whether the object is resident in
55  * lmem while in the fence signaling critical path.
56  * @obj: The object to check.
57  *
58  * This function is intended to be called from within the fence signaling
59  * path where the fence keeps the object from being migrated. For example
60  * during gpu reset or similar.
61  *
62  * Return: Whether the object is resident in lmem.
63  */
64 bool __i915_gem_object_is_lmem(struct drm_i915_gem_object *obj)
65 {
66         struct intel_memory_region *mr = READ_ONCE(obj->mm.region);
67
68 #ifdef CONFIG_LOCKDEP
69         GEM_WARN_ON(dma_resv_test_signaled(obj->base.resv, true));
70 #endif
71         return mr && (mr->type == INTEL_MEMORY_LOCAL ||
72                       mr->type == INTEL_MEMORY_STOLEN_LOCAL);
73 }
74
75 struct drm_i915_gem_object *
76 i915_gem_object_create_lmem(struct drm_i915_private *i915,
77                             resource_size_t size,
78                             unsigned int flags)
79 {
80         return i915_gem_object_create_region(i915->mm.regions[INTEL_REGION_LMEM],
81                                              size, flags);
82 }