Commit 698fa62f authored by Philip Yang's avatar Philip Yang Committed by Alex Deucher
Browse files

drm/amdgpu: Add helper to alloc GART entries



Add helper amdgpu_gtt_mgr_alloc/free_entries, define
GART_ENTRY_WITHOUT_BO_COLOR color for GART node not allocated with GTT
bo, then amdgpu_gtt_mgr_recover skip those mm_node.

Signed-off-by: default avatarPhilip Yang <Philip.Yang@amd.com>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Reviewed-by: default avatarPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent ec9243d1
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@

#include "amdgpu.h"

#define GART_ENTRY_WITHOUT_BO_COLOR	1

static inline struct amdgpu_gtt_mgr *
to_gtt_mgr(struct ttm_resource_manager *man)
{
@@ -180,6 +182,49 @@ static void amdgpu_gtt_mgr_del(struct ttm_resource_manager *man,
	kfree(node);
}

/**
 * amdgpu_gtt_mgr_alloc_entries - alloc GART entries without GTT bo
 *
 * @mgr: The GTT manager object
 * @mm_node: The drm mm node to return the new allocation node information
 * @num_pages: The number of pages for the new allocation
 * @mode: The new allocation mode
 *
 * Helper to dynamic alloc GART entries to map memory not accociated with
 * GTT BO, for example VRAM BO physical memory, remote physical memory.
 */
int amdgpu_gtt_mgr_alloc_entries(struct amdgpu_gtt_mgr *mgr,
				 struct drm_mm_node *mm_node,
				 u64 num_pages,
				 enum drm_mm_insert_mode mode)
{
	struct amdgpu_device *adev = container_of(mgr, typeof(*adev), mman.gtt_mgr);
	int r;

	spin_lock(&mgr->lock);
	r = drm_mm_insert_node_in_range(&mgr->mm, mm_node, num_pages,
					0, GART_ENTRY_WITHOUT_BO_COLOR, 0,
					adev->gmc.gart_size >> PAGE_SHIFT,
					mode);
	spin_unlock(&mgr->lock);
	return r;
}

/**
 * amdgpu_gtt_mgr_free_entries - free GART entries not accocaited with GTT bo
 *
 * @mgr: The GTT manager object
 * @mm_node: The drm mm node to free
 */
void amdgpu_gtt_mgr_free_entries(struct amdgpu_gtt_mgr *mgr,
				 struct drm_mm_node *mm_node)
{
	spin_lock(&mgr->lock);
	if (drm_mm_node_allocated(mm_node))
		drm_mm_remove_node(mm_node);
	spin_unlock(&mgr->lock);
}

/**
 * amdgpu_gtt_mgr_recover - re-init gart
 *
@@ -196,6 +241,9 @@ void amdgpu_gtt_mgr_recover(struct amdgpu_gtt_mgr *mgr)
	adev = container_of(mgr, typeof(*adev), mman.gtt_mgr);
	spin_lock(&mgr->lock);
	drm_mm_for_each_node(mm_node, &mgr->mm) {
		if (mm_node->color == GART_ENTRY_WITHOUT_BO_COLOR)
			continue;

		node = container_of(mm_node, typeof(*node), mm_nodes[0]);
		amdgpu_ttm_recover_gart(node->base.bo);
	}
+6 −0
Original line number Diff line number Diff line
@@ -141,6 +141,12 @@ void amdgpu_vram_mgr_fini(struct amdgpu_device *adev);
bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_resource *mem);
void amdgpu_gtt_mgr_recover(struct amdgpu_gtt_mgr *mgr);

int amdgpu_gtt_mgr_alloc_entries(struct amdgpu_gtt_mgr *mgr,
				 struct drm_mm_node *mm_node,
				 u64 num_pages,
				 enum drm_mm_insert_mode mode);
void amdgpu_gtt_mgr_free_entries(struct amdgpu_gtt_mgr *mgr,
				 struct drm_mm_node *mm_node);
uint64_t amdgpu_preempt_mgr_usage(struct ttm_resource_manager *man);

u64 amdgpu_vram_mgr_bo_visible_size(struct amdgpu_bo *bo);