// SPDX-License-Identifier: MIT /* * Copyright © 2021 Intel Corporation */ #include <drm/ttm/ttm_device.h> #include <drm/ttm/ttm_range_manager.h> #include "i915_drv.h" #include "i915_scatterlist.h" #include "i915_ttm_buddy_manager.h" #include "intel_region_ttm.h" #include "gem/i915_gem_region.h" #include "gem/i915_gem_ttm.h" /* For the funcs/ops export only */ /** * DOC: TTM support structure * * The code in this file deals with setting up memory managers for TTM * LMEM and MOCK regions and converting the output from * the managers to struct sg_table, Basically providing the mapping from * i915 GEM regions to TTM memory types and resource managers. */ /** * intel_region_ttm_device_init - Initialize a TTM device * @dev_priv: Pointer to an i915 device private structure. * * Return: 0 on success, negative error code on failure. */ int intel_region_ttm_device_init(struct drm_i915_private *dev_priv) { … } /** * intel_region_ttm_device_fini - Finalize a TTM device * @dev_priv: Pointer to an i915 device private structure. */ void intel_region_ttm_device_fini(struct drm_i915_private *dev_priv) { … } /* * Map the i915 memory regions to TTM memory types. We use the * driver-private types for now, reserving TTM_PL_VRAM for stolen * memory and TTM_PL_TT for GGTT use if decided to implement this. */ int intel_region_to_ttm_type(const struct intel_memory_region *mem) { … } /** * intel_region_ttm_init - Initialize a memory region for TTM. * @mem: The region to initialize. * * This function initializes a suitable TTM resource manager for the * region, and if it's a LMEM region type, attaches it to the TTM * device. MOCK regions are NOT attached to the TTM device, since we don't * have one for the mock selftests. * * Return: 0 on success, negative error code on failure. */ int intel_region_ttm_init(struct intel_memory_region *mem) { … } /** * intel_region_ttm_fini - Finalize a TTM region. * @mem: The memory region * * This functions takes down the TTM resource manager associated with the * memory region, and if it was registered with the TTM device, * removes that registration. */ int intel_region_ttm_fini(struct intel_memory_region *mem) { … } /** * intel_region_ttm_resource_to_rsgt - * Convert an opaque TTM resource manager resource to a refcounted sg_table. * @mem: The memory region. * @res: The resource manager resource obtained from the TTM resource manager. * @page_alignment: Required page alignment for each sg entry. Power of two. * * The gem backends typically use sg-tables for operations on the underlying * io_memory. So provide a way for the backends to translate the * nodes they are handed from TTM to sg-tables. * * Return: A malloced sg_table on success, an error pointer on failure. */ struct i915_refct_sgt * intel_region_ttm_resource_to_rsgt(struct intel_memory_region *mem, struct ttm_resource *res, u32 page_alignment) { … } #ifdef CONFIG_DRM_I915_SELFTEST /** * intel_region_ttm_resource_alloc - Allocate memory resources from a region * @mem: The memory region, * @offset: BO offset * @size: The requested size in bytes * @flags: Allocation flags * * This functionality is provided only for callers that need to allocate * memory from standalone TTM range managers, without the TTM eviction * functionality. Don't use if you are not completely sure that's the * case. The returned opaque node can be converted to an sg_table using * intel_region_ttm_resource_to_st(), and can be freed using * intel_region_ttm_resource_free(). * * Return: A valid pointer on success, an error pointer on failure. */ struct ttm_resource * intel_region_ttm_resource_alloc(struct intel_memory_region *mem, resource_size_t offset, resource_size_t size, unsigned int flags) { … } #endif /** * intel_region_ttm_resource_free - Free a resource allocated from a resource manager * @mem: The region the resource was allocated from. * @res: The opaque resource representing an allocation. */ void intel_region_ttm_resource_free(struct intel_memory_region *mem, struct ttm_resource *res) { … }