diff options
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_object.c')
| -rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 49 | 
1 files changed, 32 insertions, 17 deletions
| diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index 010b0cb7693c..b2a83c802bbd 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -39,6 +39,7 @@  #include "amdgpu.h"  #include "amdgpu_trace.h"  #include "amdgpu_amdkfd.h" +#include "amdgpu_vram_mgr.h"  /**   * DOC: amdgpu_object @@ -153,8 +154,10 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain)  		else  			places[c].flags |= TTM_PL_FLAG_TOPDOWN; -		if (flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS) +		if (abo->tbo.type == ttm_bo_type_kernel && +		    flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS)  			places[c].flags |= TTM_PL_FLAG_CONTIGUOUS; +  		c++;  	} @@ -173,6 +176,12 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain)  			abo->flags & AMDGPU_GEM_CREATE_PREEMPTIBLE ?  			AMDGPU_PL_PREEMPT : TTM_PL_TT;  		places[c].flags = 0; +		/* +		 * When GTT is just an alternative to VRAM make sure that we +		 * only use it as fallback and still try to fill up VRAM first. +		 */ +		if (domain & abo->preferred_domains & AMDGPU_GEM_DOMAIN_VRAM) +			places[c].flags |= TTM_PL_FLAG_FALLBACK;  		c++;  	} @@ -595,8 +604,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,  	if (!amdgpu_bo_support_uswc(bo->flags))  		bo->flags &= ~AMDGPU_GEM_CREATE_CPU_GTT_USWC; -	if (adev->ras_enabled) -		bo->flags |= AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE; +	bo->flags |= AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE;  	bo->tbo.bdev = &adev->mman.bdev;  	if (bp->domain & (AMDGPU_GEM_DOMAIN_GWS | AMDGPU_GEM_DOMAIN_OA | @@ -605,6 +613,8 @@ int amdgpu_bo_create(struct amdgpu_device *adev,  	else  		amdgpu_bo_placement_from_domain(bo, bp->domain);  	if (bp->type == ttm_bo_type_kernel) +		bo->tbo.priority = 2; +	else if (!(bp->flags & AMDGPU_GEM_CREATE_DISCARDABLE))  		bo->tbo.priority = 1;  	if (!bp->destroy) @@ -617,8 +627,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,  		return r;  	if (!amdgpu_gmc_vram_full_visible(&adev->gmc) && -	    bo->tbo.resource->mem_type == TTM_PL_VRAM && -	    amdgpu_bo_in_cpu_visible_vram(bo)) +	    amdgpu_res_cpu_visible(adev, bo->tbo.resource))  		amdgpu_cs_report_moved_bytes(adev, ctx.bytes_moved,  					     ctx.bytes_moved);  	else @@ -628,7 +637,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,  	    bo->tbo.resource->mem_type == TTM_PL_VRAM) {  		struct dma_fence *fence; -		r = amdgpu_fill_buffer(bo, 0, bo->tbo.base.resv, &fence, true); +		r = amdgpu_ttm_clear_buffer(bo, bo->tbo.base.resv, &fence);  		if (unlikely(r))  			goto fail_unreserve; @@ -758,7 +767,7 @@ int amdgpu_bo_restore_shadow(struct amdgpu_bo *shadow, struct dma_fence **fence)  	return amdgpu_copy_buffer(ring, shadow_addr, parent_addr,  				  amdgpu_bo_size(shadow), NULL, fence, -				  true, false, false); +				  true, false, 0);  }  /** @@ -960,6 +969,10 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,  		if (!bo->placements[i].lpfn ||  		    (lpfn && lpfn < bo->placements[i].lpfn))  			bo->placements[i].lpfn = lpfn; + +		if (bo->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS && +		    bo->placements[i].mem_type == TTM_PL_VRAM) +			bo->placements[i].flags |= TTM_PL_FLAG_CONTIGUOUS;  	}  	r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx); @@ -1272,23 +1285,25 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo, bool evict)  void amdgpu_bo_get_memory(struct amdgpu_bo *bo,  			  struct amdgpu_mem_stats *stats)  { +	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); +	struct ttm_resource *res = bo->tbo.resource;  	uint64_t size = amdgpu_bo_size(bo);  	struct drm_gem_object *obj;  	unsigned int domain;  	bool shared;  	/* Abort if the BO doesn't currently have a backing store */ -	if (!bo->tbo.resource) +	if (!res)  		return;  	obj = &bo->tbo.base;  	shared = drm_gem_object_is_shared_for_memory_stats(obj); -	domain = amdgpu_mem_type_to_domain(bo->tbo.resource->mem_type); +	domain = amdgpu_mem_type_to_domain(res->mem_type);  	switch (domain) {  	case AMDGPU_GEM_DOMAIN_VRAM:  		stats->vram += size; -		if (amdgpu_bo_in_cpu_visible_vram(bo)) +		if (amdgpu_res_cpu_visible(adev, bo->tbo.resource))  			stats->visible_vram += size;  		if (shared)  			stats->vram_shared += size; @@ -1359,8 +1374,9 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo)  	if (WARN_ON_ONCE(!dma_resv_trylock(bo->base.resv)))  		return; -	r = amdgpu_fill_buffer(abo, AMDGPU_POISON, bo->base.resv, &fence, true); +	r = amdgpu_fill_buffer(abo, 0, bo->base.resv, &fence, true);  	if (!WARN_ON(r)) { +		amdgpu_vram_mgr_set_cleared(bo->resource);  		amdgpu_bo_fence(abo, fence, false);  		dma_fence_put(fence);  	} @@ -1389,10 +1405,7 @@ vm_fault_t amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)  	/* Remember that this BO was accessed by the CPU */  	abo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; -	if (bo->resource->mem_type != TTM_PL_VRAM) -		return 0; - -	if (amdgpu_bo_in_cpu_visible_vram(abo)) +	if (amdgpu_res_cpu_visible(adev, bo->resource))  		return 0;  	/* Can't move a pinned BO to visible VRAM */ @@ -1415,7 +1428,7 @@ vm_fault_t amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)  	/* this should never happen */  	if (bo->resource->mem_type == TTM_PL_VRAM && -	    !amdgpu_bo_in_cpu_visible_vram(abo)) +	    !amdgpu_res_cpu_visible(adev, bo->resource))  		return VM_FAULT_SIGBUS;  	ttm_bo_move_to_lru_tail_unlocked(bo); @@ -1579,6 +1592,7 @@ uint32_t amdgpu_bo_get_preferred_domain(struct amdgpu_device *adev,   */  u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m)  { +	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);  	struct dma_buf_attachment *attachment;  	struct dma_buf *dma_buf;  	const char *placement; @@ -1587,10 +1601,11 @@ u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m)  	if (dma_resv_trylock(bo->tbo.base.resv)) {  		unsigned int domain; +  		domain = amdgpu_mem_type_to_domain(bo->tbo.resource->mem_type);  		switch (domain) {  		case AMDGPU_GEM_DOMAIN_VRAM: -			if (amdgpu_bo_in_cpu_visible_vram(bo)) +			if (amdgpu_res_cpu_visible(adev, bo->tbo.resource))  				placement = "VRAM VISIBLE";  			else  				placement = "VRAM"; |