]> Git Repo - linux.git/blobdiff - drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
Merge tag 'drm-misc-next-2017-08-08' of git://anongit.freedesktop.org/git/drm-misc...
[linux.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_object.c
index 8ee69652be8ceea145129cefb46ab46920744a74..3ec43cf9ad78fc17420dcf8c4be86173e20d9ff3 100644 (file)
@@ -93,6 +93,7 @@ static void amdgpu_ttm_bo_destroy(struct ttm_buffer_object *tbo)
 
        bo = container_of(tbo, struct amdgpu_bo, tbo);
 
+       amdgpu_bo_kunmap(bo);
        amdgpu_update_memory_usage(adev, &bo->tbo.mem, NULL);
 
        drm_gem_object_release(&bo->gem_base);
@@ -322,7 +323,7 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
        struct amdgpu_bo *bo;
        enum ttm_bo_type type;
        unsigned long page_align;
-       u64 initial_bytes_moved;
+       u64 initial_bytes_moved, bytes_moved;
        size_t acc_size;
        int r;
 
@@ -398,8 +399,14 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
        r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, type,
                                 &bo->placement, page_align, !kernel, NULL,
                                 acc_size, sg, resv, &amdgpu_ttm_bo_destroy);
-       amdgpu_cs_report_moved_bytes(adev,
-               atomic64_read(&adev->num_bytes_moved) - initial_bytes_moved);
+       bytes_moved = atomic64_read(&adev->num_bytes_moved) -
+                     initial_bytes_moved;
+       if (adev->mc.visible_vram_size < adev->mc.real_vram_size &&
+           bo->tbo.mem.mem_type == TTM_PL_VRAM &&
+           bo->tbo.mem.start < adev->mc.visible_vram_size >> PAGE_SHIFT)
+               amdgpu_cs_report_moved_bytes(adev, bytes_moved, bytes_moved);
+       else
+               amdgpu_cs_report_moved_bytes(adev, bytes_moved, 0);
 
        if (unlikely(r != 0))
                return r;
@@ -426,6 +433,10 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
 
        trace_amdgpu_bo_create(bo);
 
+       /* Treat CPU_ACCESS_REQUIRED only as a hint if given by UMD */
+       if (type == ttm_bo_type_device)
+               bo->flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
+
        return 0;
 
 fail_unreserve:
@@ -535,7 +546,7 @@ int amdgpu_bo_backup_to_shadow(struct amdgpu_device *adev,
 
        r = amdgpu_copy_buffer(ring, bo_addr, shadow_addr,
                               amdgpu_bo_size(bo), resv, fence,
-                              direct);
+                              direct, false);
        if (!r)
                amdgpu_bo_fence(bo, *fence, true);
 
@@ -588,7 +599,7 @@ int amdgpu_bo_restore_from_shadow(struct amdgpu_device *adev,
 
        r = amdgpu_copy_buffer(ring, shadow_addr, bo_addr,
                               amdgpu_bo_size(bo), resv, fence,
-                              direct);
+                              direct, false);
        if (!r)
                amdgpu_bo_fence(bo, *fence, true);
 
@@ -724,15 +735,16 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
                dev_err(adev->dev, "%p pin failed\n", bo);
                goto error;
        }
-       r = amdgpu_ttm_bind(&bo->tbo, &bo->tbo.mem);
-       if (unlikely(r)) {
-               dev_err(adev->dev, "%p bind failed\n", bo);
-               goto error;
-       }
 
        bo->pin_count = 1;
-       if (gpu_addr != NULL)
+       if (gpu_addr != NULL) {
+               r = amdgpu_ttm_bind(&bo->tbo, &bo->tbo.mem);
+               if (unlikely(r)) {
+                       dev_err(adev->dev, "%p bind failed\n", bo);
+                       goto error;
+               }
                *gpu_addr = amdgpu_bo_gpu_offset(bo);
+       }
        if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
                adev->vram_pin_size += amdgpu_bo_size(bo);
                if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)
@@ -921,6 +933,8 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo,
        abo = container_of(bo, struct amdgpu_bo, tbo);
        amdgpu_vm_bo_invalidate(adev, abo);
 
+       amdgpu_bo_kunmap(abo);
+
        /* remember the eviction */
        if (evict)
                atomic64_inc(&adev->num_evictions);
@@ -939,19 +953,22 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
 {
        struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev);
        struct amdgpu_bo *abo;
-       unsigned long offset, size, lpfn;
-       int i, r;
+       unsigned long offset, size;
+       int r;
 
        if (!amdgpu_ttm_bo_is_amdgpu_bo(bo))
                return 0;
 
        abo = container_of(bo, struct amdgpu_bo, tbo);
+
+       /* Remember that this BO was accessed by the CPU */
+       abo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
+
        if (bo->mem.mem_type != TTM_PL_VRAM)
                return 0;
 
        size = bo->mem.num_pages << PAGE_SHIFT;
        offset = bo->mem.start << PAGE_SHIFT;
-       /* TODO: figure out how to map scattered VRAM to the CPU */
        if ((offset + size) <= adev->mc.visible_vram_size)
                return 0;
 
@@ -961,26 +978,21 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
 
        /* hurrah the memory is not visible ! */
        atomic64_inc(&adev->num_vram_cpu_page_faults);
-       amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_VRAM);
-       lpfn =  adev->mc.visible_vram_size >> PAGE_SHIFT;
-       for (i = 0; i < abo->placement.num_placement; i++) {
-               /* Force into visible VRAM */
-               if ((abo->placements[i].flags & TTM_PL_FLAG_VRAM) &&
-                   (!abo->placements[i].lpfn ||
-                    abo->placements[i].lpfn > lpfn))
-                       abo->placements[i].lpfn = lpfn;
-       }
+       amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_VRAM |
+                                        AMDGPU_GEM_DOMAIN_GTT);
+
+       /* Avoid costly evictions; only set GTT as a busy placement */
+       abo->placement.num_busy_placement = 1;
+       abo->placement.busy_placement = &abo->placements[1];
+
        r = ttm_bo_validate(bo, &abo->placement, false, false);
-       if (unlikely(r == -ENOMEM)) {
-               amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_GTT);
-               return ttm_bo_validate(bo, &abo->placement, false, false);
-       } else if (unlikely(r != 0)) {
+       if (unlikely(r != 0))
                return r;
-       }
 
        offset = bo->mem.start << PAGE_SHIFT;
        /* this should never happen */
-       if ((offset + size) > adev->mc.visible_vram_size)
+       if (bo->mem.mem_type == TTM_PL_VRAM &&
+           (offset + size) > adev->mc.visible_vram_size)
                return -EINVAL;
 
        return 0;
This page took 0.039515 seconds and 4 git commands to generate.