drm/amdgpu: cleanup kptr handling
authorChristian König <christian.koenig@amd.com>
Thu, 20 Jul 2017 21:45:18 +0000 (23:45 +0200)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 15 Aug 2017 18:45:53 +0000 (14:45 -0400)
Don't keep around the same pointer twice.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu.h
drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

index 0fa6438..241abc1 100644 (file)
@@ -425,7 +425,6 @@ struct amdgpu_bo {
        struct ttm_bo_kmap_obj          kmap;
        u64                             flags;
        unsigned                        pin_count;
-       void                            *kptr;
        u64                             tiling_flags;
        u64                             metadata_flags;
        void                            *metadata;
index 0a8ee24..cd95574 100644 (file)
@@ -250,7 +250,7 @@ static int amdgpufb_create(struct drm_fb_helper *helper,
        tmp = amdgpu_bo_gpu_offset(abo) - adev->mc.vram_start;
        info->fix.smem_start = adev->mc.aper_base + tmp;
        info->fix.smem_len = amdgpu_bo_size(abo);
-       info->screen_base = abo->kptr;
+       info->screen_base = amdgpu_bo_kptr(abo);
        info->screen_size = amdgpu_bo_size(abo);
 
        drm_fb_helper_fill_var(info, &rfbdev->helper, sizes->fb_width, sizes->fb_height);
index 3ec43cf..8fddea4 100644 (file)
@@ -609,16 +609,16 @@ err:
 
 int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr)
 {
-       bool is_iomem;
+       void *kptr;
        long r;
 
        if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)
                return -EPERM;
 
-       if (bo->kptr) {
-               if (ptr) {
-                       *ptr = bo->kptr;
-               }
+       kptr = amdgpu_bo_kptr(bo);
+       if (kptr) {
+               if (ptr)
+                       *ptr = kptr;
                return 0;
        }
 
@@ -631,19 +631,23 @@ int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr)
        if (r)
                return r;
 
-       bo->kptr = ttm_kmap_obj_virtual(&bo->kmap, &is_iomem);
        if (ptr)
-               *ptr = bo->kptr;
+               *ptr = amdgpu_bo_kptr(bo);
 
        return 0;
 }
 
+void *amdgpu_bo_kptr(struct amdgpu_bo *bo)
+{
+       bool is_iomem;
+
+       return ttm_kmap_obj_virtual(&bo->kmap, &is_iomem);
+}
+
 void amdgpu_bo_kunmap(struct amdgpu_bo *bo)
 {
-       if (bo->kptr == NULL)
-               return;
-       bo->kptr = NULL;
-       ttm_bo_kunmap(&bo->kmap);
+       if (bo->kmap.bo)
+               ttm_bo_kunmap(&bo->kmap);
 }
 
 struct amdgpu_bo *amdgpu_bo_ref(struct amdgpu_bo *bo)
index 833b172..f53d53d 100644 (file)
@@ -147,6 +147,7 @@ int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
 void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr,
                           void **cpu_addr);
 int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr);
+void *amdgpu_bo_kptr(struct amdgpu_bo *bo);
 void amdgpu_bo_kunmap(struct amdgpu_bo *bo);
 struct amdgpu_bo *amdgpu_bo_ref(struct amdgpu_bo *bo);
 void amdgpu_bo_unref(struct amdgpu_bo **bo);
index 250c8e8..9255c3e 100644 (file)
@@ -1060,7 +1060,7 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev,
        shadow = parent->bo->shadow;
 
        if (vm->use_cpu_for_update) {
-               pd_addr = (unsigned long)parent->bo->kptr;
+               pd_addr = (unsigned long)amdgpu_bo_kptr(parent->bo);
                r = amdgpu_vm_wait_pd(adev, vm, AMDGPU_FENCE_OWNER_VM);
                if (unlikely(r))
                        return r;
@@ -1401,7 +1401,7 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,
 
                pt = entry->bo;
                if (use_cpu_update) {
-                       pe_start = (unsigned long)pt->kptr;
+                       pe_start = (unsigned long)amdgpu_bo_kptr(pt);
                } else {
                        if (pt->shadow) {
                                pe_start = amdgpu_bo_gpu_offset(pt->shadow);