Hi,

Le 15/12/2025 à 17:56, Philip Yang a écrit :
Add helper amdgpu_gtt_mgr_alloc/free_entries, define GART_ENTRY_WITOUT_BO_COLOR
color for GART node not allocated with GTT bo, then amdgpu_gtt_mgr_recover skip
those mm_node.

Signed-off-by: Philip Yang <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 48 +++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h     |  6 +++
  2 files changed, 54 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index 895c1e4c6747..285177070895 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -26,6 +26,8 @@
#include "amdgpu.h" +#define GART_ENTRY_WITOUT_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_WITOUT_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_WITOUT_BO_COLOR)
+                       continue;
+
                node = container_of(mm_node, typeof(*node), mm_nodes[0]);
                amdgpu_ttm_recover_gart(node->base.bo);
        }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
index 72488124aa59..25640bed7dc9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
@@ -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 *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);


Reviewed-by: Pierre-Eric Pelloux-Prayer <[email protected]>

Thanks!

Reply via email to