1 // SPDX-License-Identifier: MIT
3 * Copyright © 2019 Intel Corporation
6 #include "intel_memory_region.h"
7 #include "gem/i915_gem_region.h"
8 #include "gem/i915_gem_lmem.h"
12 i915_gem_object_lmem_io_map(struct drm_i915_gem_object *obj,
16 resource_size_t offset;
18 GEM_BUG_ON(!i915_gem_object_is_contiguous(obj));
20 offset = i915_gem_object_get_dma_address(obj, n);
21 offset -= obj->mm.region->region.start;
23 return io_mapping_map_wc(&obj->mm.region->iomap, offset, size);
27 * i915_gem_object_is_lmem - Whether the object is resident in
29 * @obj: The object to check.
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.
37 * Return: Whether the object migratable but resident in lmem, or not
38 * migratable and will be present in lmem when valid.
40 bool i915_gem_object_is_lmem(struct drm_i915_gem_object *obj)
42 struct intel_memory_region *mr = READ_ONCE(obj->mm.region);
45 if (i915_gem_object_migratable(obj) &&
46 i915_gem_object_evictable(obj))
47 assert_object_held(obj);
49 return mr && (mr->type == INTEL_MEMORY_LOCAL ||
50 mr->type == INTEL_MEMORY_STOLEN_LOCAL);
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.
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.
62 * Return: Whether the object is resident in lmem.
64 bool __i915_gem_object_is_lmem(struct drm_i915_gem_object *obj)
66 struct intel_memory_region *mr = READ_ONCE(obj->mm.region);
69 GEM_WARN_ON(dma_resv_test_signaled(obj->base.resv, true));
71 return mr && (mr->type == INTEL_MEMORY_LOCAL ||
72 mr->type == INTEL_MEMORY_STOLEN_LOCAL);
75 struct drm_i915_gem_object *
76 i915_gem_object_create_lmem(struct drm_i915_private *i915,
80 return i915_gem_object_create_region(i915->mm.regions[INTEL_REGION_LMEM],