@@ -133,7 +133,7 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
133133
134134 } else if (!amdgpu_gmc_vram_full_visible (& adev -> gmc ) &&
135135 !(abo -> flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ) &&
136- amdgpu_bo_in_cpu_visible_vram ( abo )) {
136+ amdgpu_res_cpu_visible ( adev , bo -> resource )) {
137137
138138 /* Try evicting to the CPU inaccessible part of VRAM
139139 * first, but only set GTT as busy placement, so this
@@ -403,40 +403,55 @@ static int amdgpu_move_blit(struct ttm_buffer_object *bo,
403403 return r ;
404404}
405405
406- /*
407- * amdgpu_mem_visible - Check that memory can be accessed by ttm_bo_move_memcpy
406+ /**
407+ * amdgpu_res_cpu_visible - Check that resource can be accessed by CPU
408+ * @adev: amdgpu device
409+ * @res: the resource to check
408410 *
409- * Called by amdgpu_bo_move()
411+ * Returns: true if the full resource is CPU visible, false otherwise.
410412 */
411- static bool amdgpu_mem_visible (struct amdgpu_device * adev ,
412- struct ttm_resource * mem )
413+ bool amdgpu_res_cpu_visible (struct amdgpu_device * adev ,
414+ struct ttm_resource * res )
413415{
414- u64 mem_size = (u64 )mem -> size ;
415416 struct amdgpu_res_cursor cursor ;
416- u64 end ;
417417
418- if (mem -> mem_type == TTM_PL_SYSTEM ||
419- mem -> mem_type == TTM_PL_TT )
418+ if (!res )
419+ return false;
420+
421+ if (res -> mem_type == TTM_PL_SYSTEM || res -> mem_type == TTM_PL_TT ||
422+ res -> mem_type == AMDGPU_PL_PREEMPT )
420423 return true;
421- if (mem -> mem_type != TTM_PL_VRAM )
424+
425+ if (res -> mem_type != TTM_PL_VRAM )
422426 return false;
423427
424- amdgpu_res_first (mem , 0 , mem_size , & cursor );
425- end = cursor .start + cursor .size ;
428+ amdgpu_res_first (res , 0 , res -> size , & cursor );
426429 while (cursor .remaining ) {
430+ if ((cursor .start + cursor .size ) >= adev -> gmc .visible_vram_size )
431+ return false;
427432 amdgpu_res_next (& cursor , cursor .size );
433+ }
428434
429- if (! cursor . remaining )
430- break ;
435+ return true;
436+ }
431437
432- /* ttm_resource_ioremap only supports contiguous memory */
433- if (end != cursor .start )
434- return false;
438+ /*
439+ * amdgpu_res_copyable - Check that memory can be accessed by ttm_bo_move_memcpy
440+ *
441+ * Called by amdgpu_bo_move()
442+ */
443+ static bool amdgpu_res_copyable (struct amdgpu_device * adev ,
444+ struct ttm_resource * mem )
445+ {
446+ if (!amdgpu_res_cpu_visible (adev , mem ))
447+ return false;
435448
436- end = cursor .start + cursor .size ;
437- }
449+ /* ttm_resource_ioremap only supports contiguous memory */
450+ if (mem -> mem_type == TTM_PL_VRAM &&
451+ !(mem -> placement & TTM_PL_FLAG_CONTIGUOUS ))
452+ return false;
438453
439- return end <= adev -> gmc . visible_vram_size ;
454+ return true ;
440455}
441456
442457/*
@@ -529,8 +544,8 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
529544
530545 if (r ) {
531546 /* Check that all memory is CPU accessible */
532- if (!amdgpu_mem_visible (adev , old_mem ) ||
533- !amdgpu_mem_visible (adev , new_mem )) {
547+ if (!amdgpu_res_copyable (adev , old_mem ) ||
548+ !amdgpu_res_copyable (adev , new_mem )) {
534549 pr_err ("Move buffer fallback to memcpy unavailable\n" );
535550 return r ;
536551 }
@@ -557,7 +572,6 @@ static int amdgpu_ttm_io_mem_reserve(struct ttm_device *bdev,
557572 struct ttm_resource * mem )
558573{
559574 struct amdgpu_device * adev = amdgpu_ttm_adev (bdev );
560- size_t bus_size = (size_t )mem -> size ;
561575
562576 switch (mem -> mem_type ) {
563577 case TTM_PL_SYSTEM :
@@ -568,9 +582,6 @@ static int amdgpu_ttm_io_mem_reserve(struct ttm_device *bdev,
568582 break ;
569583 case TTM_PL_VRAM :
570584 mem -> bus .offset = mem -> start << PAGE_SHIFT ;
571- /* check if it's visible */
572- if ((mem -> bus .offset + bus_size ) > adev -> gmc .visible_vram_size )
573- return - EINVAL ;
574585
575586 if (adev -> mman .aper_base_kaddr &&
576587 mem -> placement & TTM_PL_FLAG_CONTIGUOUS )
0 commit comments