Skip to content

Commit 698fa62

Browse files
amd-yangpalexdeucher
authored andcommitted
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: Philip Yang <Philip.Yang@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com> Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent ec9243d commit 698fa62

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#include "amdgpu.h"
2828

29+
#define GART_ENTRY_WITHOUT_BO_COLOR 1
30+
2931
static inline struct amdgpu_gtt_mgr *
3032
to_gtt_mgr(struct ttm_resource_manager *man)
3133
{
@@ -180,6 +182,49 @@ static void amdgpu_gtt_mgr_del(struct ttm_resource_manager *man,
180182
kfree(node);
181183
}
182184

185+
/**
186+
* amdgpu_gtt_mgr_alloc_entries - alloc GART entries without GTT bo
187+
*
188+
* @mgr: The GTT manager object
189+
* @mm_node: The drm mm node to return the new allocation node information
190+
* @num_pages: The number of pages for the new allocation
191+
* @mode: The new allocation mode
192+
*
193+
* Helper to dynamic alloc GART entries to map memory not accociated with
194+
* GTT BO, for example VRAM BO physical memory, remote physical memory.
195+
*/
196+
int amdgpu_gtt_mgr_alloc_entries(struct amdgpu_gtt_mgr *mgr,
197+
struct drm_mm_node *mm_node,
198+
u64 num_pages,
199+
enum drm_mm_insert_mode mode)
200+
{
201+
struct amdgpu_device *adev = container_of(mgr, typeof(*adev), mman.gtt_mgr);
202+
int r;
203+
204+
spin_lock(&mgr->lock);
205+
r = drm_mm_insert_node_in_range(&mgr->mm, mm_node, num_pages,
206+
0, GART_ENTRY_WITHOUT_BO_COLOR, 0,
207+
adev->gmc.gart_size >> PAGE_SHIFT,
208+
mode);
209+
spin_unlock(&mgr->lock);
210+
return r;
211+
}
212+
213+
/**
214+
* amdgpu_gtt_mgr_free_entries - free GART entries not accocaited with GTT bo
215+
*
216+
* @mgr: The GTT manager object
217+
* @mm_node: The drm mm node to free
218+
*/
219+
void amdgpu_gtt_mgr_free_entries(struct amdgpu_gtt_mgr *mgr,
220+
struct drm_mm_node *mm_node)
221+
{
222+
spin_lock(&mgr->lock);
223+
if (drm_mm_node_allocated(mm_node))
224+
drm_mm_remove_node(mm_node);
225+
spin_unlock(&mgr->lock);
226+
}
227+
183228
/**
184229
* amdgpu_gtt_mgr_recover - re-init gart
185230
*
@@ -196,6 +241,9 @@ void amdgpu_gtt_mgr_recover(struct amdgpu_gtt_mgr *mgr)
196241
adev = container_of(mgr, typeof(*adev), mman.gtt_mgr);
197242
spin_lock(&mgr->lock);
198243
drm_mm_for_each_node(mm_node, &mgr->mm) {
244+
if (mm_node->color == GART_ENTRY_WITHOUT_BO_COLOR)
245+
continue;
246+
199247
node = container_of(mm_node, typeof(*node), mm_nodes[0]);
200248
amdgpu_ttm_recover_gart(node->base.bo);
201249
}

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ void amdgpu_vram_mgr_fini(struct amdgpu_device *adev);
141141
bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_resource *mem);
142142
void amdgpu_gtt_mgr_recover(struct amdgpu_gtt_mgr *mgr);
143143

144+
int amdgpu_gtt_mgr_alloc_entries(struct amdgpu_gtt_mgr *mgr,
145+
struct drm_mm_node *mm_node,
146+
u64 num_pages,
147+
enum drm_mm_insert_mode mode);
148+
void amdgpu_gtt_mgr_free_entries(struct amdgpu_gtt_mgr *mgr,
149+
struct drm_mm_node *mm_node);
144150
uint64_t amdgpu_preempt_mgr_usage(struct ttm_resource_manager *man);
145151

146152
u64 amdgpu_vram_mgr_bo_visible_size(struct amdgpu_bo *bo);

0 commit comments

Comments
 (0)