drm/amdkfd: get doorbell's absolute offset based on the db_size
authorArvind Yadav <Arvind.Yadav@amd.com>
Mon, 9 Oct 2023 17:13:16 +0000 (22:43 +0530)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 9 Oct 2023 21:02:34 +0000 (17:02 -0400)
Here, Adding db_size in byte to find the doorbell's
absolute offset for both 32-bit and 64-bit doorbell sizes.
So that doorbell offset will be aligned based on the doorbell
size.

v2:
- Addressed the review comment from Felix.
v3:
- Adding doorbell_size as parameter to get db absolute offset.
v4:
  Squash the two patches into one.

Cc: Christian Koenig <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Shashank Sharma <shashank.sharma@amd.com>
Signed-off-by: Arvind Yadav <Arvind.Yadav@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h
drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell_mgr.c
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c

index b0edeed..2675689 100644 (file)
@@ -360,8 +360,9 @@ int amdgpu_doorbell_init(struct amdgpu_device *adev);
 void amdgpu_doorbell_fini(struct amdgpu_device *adev);
 int amdgpu_doorbell_create_kernel_doorbells(struct amdgpu_device *adev);
 uint32_t amdgpu_doorbell_index_on_bar(struct amdgpu_device *adev,
-                                      struct amdgpu_bo *db_bo,
-                                      uint32_t doorbell_index);
+                                     struct amdgpu_bo *db_bo,
+                                     uint32_t doorbell_index,
+                                     uint32_t db_size);
 
 #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
 #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
index d0249ad..16292d8 100644 (file)
@@ -114,19 +114,24 @@ void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v)
  * @adev: amdgpu_device pointer
  * @db_bo: doorbell object's bo
  * @doorbell_index: doorbell relative index in this doorbell object
+ * @db_size: doorbell size is in byte
  *
  * returns doorbell's absolute index in BAR
  */
 uint32_t amdgpu_doorbell_index_on_bar(struct amdgpu_device *adev,
-                                      struct amdgpu_bo *db_bo,
-                                      uint32_t doorbell_index)
+                                     struct amdgpu_bo *db_bo,
+                                     uint32_t doorbell_index,
+                                     uint32_t db_size)
 {
        int db_bo_offset;
 
        db_bo_offset = amdgpu_bo_gpu_offset_no_check(db_bo);
 
-       /* doorbell index is 32 bit but doorbell's size is 64-bit, so *2 */
-       return db_bo_offset / sizeof(u32) + doorbell_index * 2;
+       /* doorbell index is 32 bit but doorbell's size can be 32 bit
+        * or 64 bit, so *db_size(in byte)/4 for alignment.
+        */
+       return db_bo_offset / sizeof(u32) + doorbell_index *
+              DIV_ROUND_UP(db_size, 4);
 }
 
 /**
index 36e7171..c0e7154 100644 (file)
@@ -410,7 +410,8 @@ static int allocate_doorbell(struct qcm_process_device *qpd,
 
        q->properties.doorbell_off = amdgpu_doorbell_index_on_bar(dev->adev,
                                                                  qpd->proc_doorbells,
-                                                                 q->doorbell_id);
+                                                                 q->doorbell_id,
+                                                                 dev->kfd->device_info.doorbell_size);
        return 0;
 }
 
index 7b38537..05c7488 100644 (file)
@@ -161,7 +161,10 @@ void __iomem *kfd_get_kernel_doorbell(struct kfd_dev *kfd,
        if (inx >= KFD_MAX_NUM_OF_QUEUES_PER_PROCESS)
                return NULL;
 
-       *doorbell_off = amdgpu_doorbell_index_on_bar(kfd->adev, kfd->doorbells, inx);
+       *doorbell_off = amdgpu_doorbell_index_on_bar(kfd->adev,
+                                                    kfd->doorbells,
+                                                    inx,
+                                                    kfd->device_info.doorbell_size);
        inx *= 2;
 
        pr_debug("Get kernel queue doorbell\n"
@@ -240,7 +243,10 @@ phys_addr_t kfd_get_process_doorbells(struct kfd_process_device *pdd)
                        return 0;
        }
 
-       first_db_index = amdgpu_doorbell_index_on_bar(adev, pdd->qpd.proc_doorbells, 0);
+       first_db_index = amdgpu_doorbell_index_on_bar(adev,
+                                                     pdd->qpd.proc_doorbells,
+                                                     0,
+                                                     pdd->dev->kfd->device_info.doorbell_size);
        return adev->doorbell.base + first_db_index * sizeof(uint32_t);
 }
 
index adb5e4b..7764939 100644 (file)
@@ -377,7 +377,8 @@ int pqm_create_queue(struct process_queue_manager *pqm,
                 */
                uint32_t first_db_index = amdgpu_doorbell_index_on_bar(pdd->dev->adev,
                                                                       pdd->qpd.proc_doorbells,
-                                                                      0);
+                                                                      0,
+                                                                      pdd->dev->kfd->device_info.doorbell_size);
 
                *p_doorbell_offset_in_process = (q->properties.doorbell_off
                                                - first_db_index) * sizeof(uint32_t);