drm/amdkfd: Fix doorbell initialization and finalization
authorFelix Kuehling <Felix.Kuehling@amd.com>
Wed, 16 Aug 2017 03:00:10 +0000 (23:00 -0400)
committerOded Gabbay <oded.gabbay@gmail.com>
Wed, 16 Aug 2017 03:00:10 +0000 (23:00 -0400)
Handle errors in doorbell aperture initialization instead of BUG_ON.
iounmap doorbell aperture during finalization.

Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: Oded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
drivers/gpu/drm/amd/amdkfd/kfd_device.c
drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c
drivers/gpu/drm/amd/amdkfd/kfd_priv.h

index e28e8183a4523c2e7b27b1239a098d7ed29fa52b..cb7ed0294412ef3b332fa39a687127a3857238db 100644 (file)
@@ -260,7 +260,11 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,
                goto kfd_gtt_sa_init_error;
        }
 
-       kfd_doorbell_init(kfd);
+       if (kfd_doorbell_init(kfd)) {
+               dev_err(kfd_device,
+                       "Error initializing doorbell aperture\n");
+               goto kfd_doorbell_error;
+       }
 
        if (kfd_topology_add_device(kfd)) {
                dev_err(kfd_device, "Error adding device to topology\n");
@@ -315,6 +319,8 @@ device_iommu_pasid_error:
 kfd_interrupt_error:
        kfd_topology_remove_device(kfd);
 kfd_topology_add_device_error:
+       kfd_doorbell_fini(kfd);
+kfd_doorbell_error:
        kfd_gtt_sa_fini(kfd);
 kfd_gtt_sa_init_error:
        kfd->kfd2kgd->free_gtt_mem(kfd->kgd, kfd->gtt_mem);
@@ -332,6 +338,7 @@ void kgd2kfd_device_exit(struct kfd_dev *kfd)
                amd_iommu_free_device(kfd->pdev);
                kfd_interrupt_exit(kfd);
                kfd_topology_remove_device(kfd);
+               kfd_doorbell_fini(kfd);
                kfd_gtt_sa_fini(kfd);
                kfd->kfd2kgd->free_gtt_mem(kfd->kgd, kfd->gtt_mem);
        }
index 00552701e5589c29f0d850f8a66d01f9f1499b4f..acf4d2a977adf7acce0e00df05bbb211d94eda9c 100644 (file)
@@ -59,7 +59,7 @@ static inline size_t doorbell_process_allocation(void)
 }
 
 /* Doorbell calculations for device init. */
-void kfd_doorbell_init(struct kfd_dev *kfd)
+int kfd_doorbell_init(struct kfd_dev *kfd)
 {
        size_t doorbell_start_offset;
        size_t doorbell_aperture_size;
@@ -95,7 +95,8 @@ void kfd_doorbell_init(struct kfd_dev *kfd)
        kfd->doorbell_kernel_ptr = ioremap(kfd->doorbell_base,
                                                doorbell_process_allocation());
 
-       BUG_ON(!kfd->doorbell_kernel_ptr);
+       if (!kfd->doorbell_kernel_ptr)
+               return -ENOMEM;
 
        pr_debug("Doorbell initialization:\n");
        pr_debug("doorbell base           == 0x%08lX\n",
@@ -115,6 +116,14 @@ void kfd_doorbell_init(struct kfd_dev *kfd)
 
        pr_debug("doorbell kernel address == 0x%08lX\n",
                        (uintptr_t)kfd->doorbell_kernel_ptr);
+
+       return 0;
+}
+
+void kfd_doorbell_fini(struct kfd_dev *kfd)
+{
+       if (kfd->doorbell_kernel_ptr)
+               iounmap(kfd->doorbell_kernel_ptr);
 }
 
 int kfd_doorbell_mmap(struct kfd_process *process, struct vm_area_struct *vma)
index 469b7ea3fa99aeee69ee9771c81a074ec7102437..f0d55cc050a542dfea5f86a24d349b2b514e88d4 100644 (file)
@@ -576,7 +576,8 @@ unsigned int kfd_pasid_alloc(void);
 void kfd_pasid_free(unsigned int pasid);
 
 /* Doorbells */
-void kfd_doorbell_init(struct kfd_dev *kfd);
+int kfd_doorbell_init(struct kfd_dev *kfd);
+void kfd_doorbell_fini(struct kfd_dev *kfd);
 int kfd_doorbell_mmap(struct kfd_process *process, struct vm_area_struct *vma);
 u32 __iomem *kfd_get_kernel_doorbell(struct kfd_dev *kfd,
                                        unsigned int *doorbell_off);