Lines Matching +full:memory +full:- +full:region

1 // SPDX-License-Identifier: MIT
19 * The code in this file deals with setting up memory managers for TTM
22 * i915 GEM regions to TTM memory types and resource managers.
26 * intel_region_ttm_device_init - Initialize a TTM device
33 struct drm_device *drm = &dev_priv->drm; in intel_region_ttm_device_init()
35 return ttm_device_init(&dev_priv->bdev, i915_ttm_driver(), in intel_region_ttm_device_init()
36 drm->dev, drm->anon_inode->i_mapping, in intel_region_ttm_device_init()
37 drm->vma_offset_manager, false, false); in intel_region_ttm_device_init()
41 * intel_region_ttm_device_fini - Finalize a TTM device
46 ttm_device_fini(&dev_priv->bdev); in intel_region_ttm_device_fini()
50 * Map the i915 memory regions to TTM memory types. We use the
51 * driver-private types for now, reserving TTM_PL_VRAM for stolen
52 * memory and TTM_PL_TT for GGTT use if decided to implement this.
58 GEM_BUG_ON(mem->type != INTEL_MEMORY_LOCAL && in intel_region_to_ttm_type()
59 mem->type != INTEL_MEMORY_MOCK && in intel_region_to_ttm_type()
60 mem->type != INTEL_MEMORY_SYSTEM); in intel_region_to_ttm_type()
62 if (mem->type == INTEL_MEMORY_SYSTEM) in intel_region_to_ttm_type()
65 type = mem->instance + TTM_PL_PRIV; in intel_region_to_ttm_type()
72 * intel_region_ttm_init - Initialize a memory region for TTM.
73 * @mem: The region to initialize.
76 * region, and if it's a LMEM region type, attaches it to the TTM
84 struct ttm_device *bdev = &mem->i915->bdev; in intel_region_ttm_init()
89 resource_size(&mem->region), in intel_region_ttm_init()
90 resource_size(&mem->io), in intel_region_ttm_init()
91 mem->min_page_size, PAGE_SIZE); in intel_region_ttm_init()
95 mem->region_private = ttm_manager_type(bdev, mem_type); in intel_region_ttm_init()
101 * intel_region_ttm_fini - Finalize a TTM region.
102 * @mem: The memory region
105 * memory region, and if it was registered with the TTM device,
110 struct ttm_resource_manager *man = mem->region_private; in intel_region_ttm_fini()
111 int ret = -EBUSY; in intel_region_ttm_fini()
115 * Put the region's move fences. This releases requests that in intel_region_ttm_fini()
117 * objects placed in this region. in intel_region_ttm_fini()
122 /* Flush objects from region. */ in intel_region_ttm_fini()
124 i915_gem_flush_free_objects(mem->i915); in intel_region_ttm_fini()
126 mutex_lock(&mem->objects.lock); in intel_region_ttm_fini()
127 if (list_empty(&mem->objects.list)) in intel_region_ttm_fini()
129 mutex_unlock(&mem->objects.lock); in intel_region_ttm_fini()
134 drain_workqueue(mem->i915->bdev.wq); in intel_region_ttm_fini()
137 /* If we leaked objects, Don't free the region causing use after free */ in intel_region_ttm_fini()
141 ret = i915_ttm_buddy_man_fini(&mem->i915->bdev, in intel_region_ttm_fini()
144 mem->region_private = NULL; in intel_region_ttm_fini()
150 * intel_region_ttm_resource_to_rsgt -
152 * @mem: The memory region.
156 * The gem backends typically use sg-tables for operations on the underlying
158 * nodes they are handed from TTM to sg-tables.
167 if (mem->is_range_manager) { in intel_region_ttm_resource_to_rsgt()
171 return i915_rsgt_from_mm_node(&range_node->mm_nodes[0], in intel_region_ttm_resource_to_rsgt()
172 mem->region.start, in intel_region_ttm_resource_to_rsgt()
175 return i915_rsgt_from_buddy_resource(res, mem->region.start, in intel_region_ttm_resource_to_rsgt()
182 * intel_region_ttm_resource_alloc - Allocate memory resources from a region
183 * @mem: The memory region,
189 * memory from standalone TTM range managers, without the TTM eviction
203 struct ttm_resource_manager *man = mem->region_private; in intel_region_ttm_resource_alloc()
213 ret = -E2BIG; in intel_region_ttm_resource_alloc()
218 ret = -E2BIG; in intel_region_ttm_resource_alloc()
222 } else if (resource_size(&mem->io) && resource_size(&mem->io) < mem->total) { in intel_region_ttm_resource_alloc()
227 if (WARN_ON(overflows_type(resource_size(&mem->io) >> PAGE_SHIFT, place.lpfn))) { in intel_region_ttm_resource_alloc()
228 ret = -E2BIG; in intel_region_ttm_resource_alloc()
231 place.lpfn = resource_size(&mem->io) >> PAGE_SHIFT; in intel_region_ttm_resource_alloc()
236 mock_bo.bdev = &mem->i915->bdev; in intel_region_ttm_resource_alloc()
238 ret = man->func->alloc(man, &mock_bo, &place, &res); in intel_region_ttm_resource_alloc()
241 if (ret == -ENOSPC) in intel_region_ttm_resource_alloc()
242 ret = -ENXIO; in intel_region_ttm_resource_alloc()
244 res->bo = NULL; /* Rather blow up, then some uaf */ in intel_region_ttm_resource_alloc()
251 * intel_region_ttm_resource_free - Free a resource allocated from a resource manager
252 * @mem: The region the resource was allocated from.
258 struct ttm_resource_manager *man = mem->region_private; in intel_region_ttm_resource_free()
261 mock_bo.base.size = res->size; in intel_region_ttm_resource_free()
262 mock_bo.bdev = &mem->i915->bdev; in intel_region_ttm_resource_free()
263 res->bo = &mock_bo; in intel_region_ttm_resource_free()
265 man->func->free(man, res); in intel_region_ttm_resource_free()