mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	drm/amdgpu: Implement intersect/compatible functions
Implemented a new intersect and compatible callback function fetching start offset from backend drm buddy allocator. Signed-off-by: Christian König <christian.koenig@amd.com> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com> Link: https://patchwork.freedesktop.org/patch/msgid/20220820073304.178444-3-Arunpravin.PaneerSelvam@amd.com
This commit is contained in:
		
							parent
							
								
									75ba3121ac
								
							
						
					
					
						commit
						ded910f368
					
				
					 2 changed files with 106 additions and 0 deletions
				
			
		| 
						 | 
					@ -204,6 +204,42 @@ void amdgpu_gtt_mgr_recover(struct amdgpu_gtt_mgr *mgr)
 | 
				
			||||||
	amdgpu_gart_invalidate_tlb(adev);
 | 
						amdgpu_gart_invalidate_tlb(adev);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * amdgpu_gtt_mgr_intersects - test for intersection
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @man: Our manager object
 | 
				
			||||||
 | 
					 * @res: The resource to test
 | 
				
			||||||
 | 
					 * @place: The place for the new allocation
 | 
				
			||||||
 | 
					 * @size: The size of the new allocation
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Simplified intersection test, only interesting if we need GART or not.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static bool amdgpu_gtt_mgr_intersects(struct ttm_resource_manager *man,
 | 
				
			||||||
 | 
									      struct ttm_resource *res,
 | 
				
			||||||
 | 
									      const struct ttm_place *place,
 | 
				
			||||||
 | 
									      size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return !place->lpfn || amdgpu_gtt_mgr_has_gart_addr(res);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * amdgpu_gtt_mgr_compatible - test for compatibility
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @man: Our manager object
 | 
				
			||||||
 | 
					 * @res: The resource to test
 | 
				
			||||||
 | 
					 * @place: The place for the new allocation
 | 
				
			||||||
 | 
					 * @size: The size of the new allocation
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Simplified compatibility test.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static bool amdgpu_gtt_mgr_compatible(struct ttm_resource_manager *man,
 | 
				
			||||||
 | 
									      struct ttm_resource *res,
 | 
				
			||||||
 | 
									      const struct ttm_place *place,
 | 
				
			||||||
 | 
									      size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return !place->lpfn || amdgpu_gtt_mgr_has_gart_addr(res);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * amdgpu_gtt_mgr_debug - dump VRAM table
 | 
					 * amdgpu_gtt_mgr_debug - dump VRAM table
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					@ -225,6 +261,8 @@ static void amdgpu_gtt_mgr_debug(struct ttm_resource_manager *man,
 | 
				
			||||||
static const struct ttm_resource_manager_func amdgpu_gtt_mgr_func = {
 | 
					static const struct ttm_resource_manager_func amdgpu_gtt_mgr_func = {
 | 
				
			||||||
	.alloc = amdgpu_gtt_mgr_new,
 | 
						.alloc = amdgpu_gtt_mgr_new,
 | 
				
			||||||
	.free = amdgpu_gtt_mgr_del,
 | 
						.free = amdgpu_gtt_mgr_del,
 | 
				
			||||||
 | 
						.intersects = amdgpu_gtt_mgr_intersects,
 | 
				
			||||||
 | 
						.compatible = amdgpu_gtt_mgr_compatible,
 | 
				
			||||||
	.debug = amdgpu_gtt_mgr_debug
 | 
						.debug = amdgpu_gtt_mgr_debug
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -720,6 +720,72 @@ uint64_t amdgpu_vram_mgr_vis_usage(struct amdgpu_vram_mgr *mgr)
 | 
				
			||||||
	return atomic64_read(&mgr->vis_usage);
 | 
						return atomic64_read(&mgr->vis_usage);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * amdgpu_vram_mgr_intersects - test each drm buddy block for intersection
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @man: TTM memory type manager
 | 
				
			||||||
 | 
					 * @res: The resource to test
 | 
				
			||||||
 | 
					 * @place: The place to test against
 | 
				
			||||||
 | 
					 * @size: Size of the new allocation
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Test each drm buddy block for intersection for eviction decision.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static bool amdgpu_vram_mgr_intersects(struct ttm_resource_manager *man,
 | 
				
			||||||
 | 
									       struct ttm_resource *res,
 | 
				
			||||||
 | 
									       const struct ttm_place *place,
 | 
				
			||||||
 | 
									       size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct amdgpu_vram_mgr_resource *mgr = to_amdgpu_vram_mgr_resource(res);
 | 
				
			||||||
 | 
						struct drm_buddy_block *block;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Check each drm buddy block individually */
 | 
				
			||||||
 | 
						list_for_each_entry(block, &mgr->blocks, link) {
 | 
				
			||||||
 | 
							unsigned long fpfn =
 | 
				
			||||||
 | 
								amdgpu_vram_mgr_block_start(block) >> PAGE_SHIFT;
 | 
				
			||||||
 | 
							unsigned long lpfn = fpfn +
 | 
				
			||||||
 | 
								(amdgpu_vram_mgr_block_size(block) >> PAGE_SHIFT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (place->fpfn < lpfn &&
 | 
				
			||||||
 | 
							    (place->lpfn && place->lpfn > fpfn))
 | 
				
			||||||
 | 
								return true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * amdgpu_vram_mgr_compatible - test each drm buddy block for compatibility
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @man: TTM memory type manager
 | 
				
			||||||
 | 
					 * @res: The resource to test
 | 
				
			||||||
 | 
					 * @place: The place to test against
 | 
				
			||||||
 | 
					 * @size: Size of the new allocation
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Test each drm buddy block for placement compatibility.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static bool amdgpu_vram_mgr_compatible(struct ttm_resource_manager *man,
 | 
				
			||||||
 | 
									       struct ttm_resource *res,
 | 
				
			||||||
 | 
									       const struct ttm_place *place,
 | 
				
			||||||
 | 
									       size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct amdgpu_vram_mgr_resource *mgr = to_amdgpu_vram_mgr_resource(res);
 | 
				
			||||||
 | 
						struct drm_buddy_block *block;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Check each drm buddy block individually */
 | 
				
			||||||
 | 
						list_for_each_entry(block, &mgr->blocks, link) {
 | 
				
			||||||
 | 
							unsigned long fpfn =
 | 
				
			||||||
 | 
								amdgpu_vram_mgr_block_start(block) >> PAGE_SHIFT;
 | 
				
			||||||
 | 
							unsigned long lpfn = fpfn +
 | 
				
			||||||
 | 
								(amdgpu_vram_mgr_block_size(block) >> PAGE_SHIFT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (fpfn < place->fpfn ||
 | 
				
			||||||
 | 
							    (place->lpfn && lpfn > place->lpfn))
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * amdgpu_vram_mgr_debug - dump VRAM table
 | 
					 * amdgpu_vram_mgr_debug - dump VRAM table
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					@ -753,6 +819,8 @@ static void amdgpu_vram_mgr_debug(struct ttm_resource_manager *man,
 | 
				
			||||||
static const struct ttm_resource_manager_func amdgpu_vram_mgr_func = {
 | 
					static const struct ttm_resource_manager_func amdgpu_vram_mgr_func = {
 | 
				
			||||||
	.alloc	= amdgpu_vram_mgr_new,
 | 
						.alloc	= amdgpu_vram_mgr_new,
 | 
				
			||||||
	.free	= amdgpu_vram_mgr_del,
 | 
						.free	= amdgpu_vram_mgr_del,
 | 
				
			||||||
 | 
						.intersects = amdgpu_vram_mgr_intersects,
 | 
				
			||||||
 | 
						.compatible = amdgpu_vram_mgr_compatible,
 | 
				
			||||||
	.debug	= amdgpu_vram_mgr_debug
 | 
						.debug	= amdgpu_vram_mgr_debug
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue