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 0fa6438c152caf197d047a44690eb230a937a250..241abc140896f84cb1959c9b99eb53bf6ec4f6cb 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 0a8ee24111803f3549c5e80214b0b4d4ac836bb9..cd95574705ee630773b4b186d96dedc1d202e9ab 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 3ec43cf9ad78fc17420dcf8c4be86173e20d9ff3..8fddea4bc1460711e84fe1f6fb2998a1d92cfde4 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 833b172a2c2a8b6cae6ca3b6dba3054ba35ba15b..f53d53d7a0af6f43812886ed2869433e3fda6d1e 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 250c8e80e646bbf800143937b6c96f6e065235ca..9255c3e579fc4ace74f277e22c333812687ea6c7 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);