Skip to contentSkip to conversation

Allocate and map doorbell based on requests

PATCH Superseded Saleemkhan Jamadar 2 participants 7 messages Jan 6, 2025 – Jan 8, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Allocate and map doorbell based on requests

Hi,

Why:
The current implementation of doorbell mapping does not handle the IP specific doorbell size and offset range. Multiple doorbell allocation when requested cannot be allocated due hard use of "struct amdgpu_usermode_queue" parameters. But these parameters vary for each request of doorbell mapping. For example VCN needs to allocate AGDB(Aggregate doorbell) and per instance doorbell. Parameters db_handle buffer allocated in userspace)and db_offset vary with respect to VCN AGDB and per instance doorbell. When compared to GFX apart from above two parameters db_size is also different.

How:
Introduce another structure to locally populate the varying parameters. Modify the the door mapping api to use these structure parameters to get db_size and offset range based on the queue type.

Regards,
Saleem

Saleemkhan Jamadar (3):
drm/amdgpu: add stucture to populate dorrbell info drm/amdgpu: map doorbell for the requested userq drm/amdgpu: add doorbell size and offset range for VCN and VPE

 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 42 ++++++++++++++-----
 .../gpu/drm/amd/include/amdgpu_userqueue.h    | 12 ++++++
 2 files changed, 43 insertions(+), 11 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/3 drm/amdgpu: add stucture to populate doorbell info

This structure basically used to the populate the doorbell information that is required to be mapped.

---
 drivers/gpu/drm/amd/include/amdgpu_userqueue.h | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +7 -0
index e7e8d79b689d..1109144ed7e0 100644
@@ -78,6 +78,13 @@ struct amdgpu_userq_mgr {
 	struct delayed_work		resume_work;
 };
 
+struct amdgpu_db_info {
+	uint64_t doorbell_handle;
+	uint32_t queue_type;
+	uint32_t doorbell_offset;
+	struct amdgpu_userq_obj	*db_obj;
+};
+
 int amdgpu_userq_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
 
 int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev);
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/3] drm/amdgpu: add stucture to populate doorbell info

Hello Saleem,

Quoted 13 lines · Saleemkhan Jamadar

This structure basically used to the populate the doorbell information that is required to be mapped.

---
  drivers/gpu/drm/amd/include/amdgpu_userqueue.h | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +0 -0
index e7e8d79b689d..1109144ed7e0 100644

drivers/gpu/drm/amd/include/amdgpu_userqueue.h struct amdgpu_userq_mgr { · line 87

Quoted 10 lines
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +7 -0
@@ -78,6 +78,13 @@ struct amdgpu_userq_mgr {
  	struct delayed_work		resume_work;
  };
 
+struct amdgpu_db_info {
+	uint64_t doorbell_handle;
+	uint32_t queue_type;
+	uint32_t doorbell_offset;
+	struct amdgpu_userq_obj	*db_obj;
+};
+

This patch can be squashed with second patch of the series.

- Shashank

Quoted 3 lines
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +0 -0
  int amdgpu_userq_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
 
  int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev);
#3 lore raw

PATCH 2/3 drm/amdgpu: map doorbell for the requested userq

In reply to Saleemkhan Jamadar

Made changes to the doorbell mapping func more generic, by taking parameters that vary based on IPs and/or usecase into db_info structure.

]

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 27 +++++++++++--------
 .../gpu/drm/amd/include/amdgpu_userqueue.h    |  5 ++++
 2 files changed, 21 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +16 -11
index 85baba323ba5..769154223e2d 100644
@@ -189,18 +189,17 @@ void amdgpu_userqueue_destroy_object(struct amdgpu_userq_mgr *uq_mgr,
 	amdgpu_bo_unref(&userq_obj->obj);
 }
 
-static uint64_t
+uint64_t
 amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
-				     struct amdgpu_usermode_queue *queue,
-				     struct drm_file *filp,
-				     uint32_t doorbell_offset)
+				     struct amdgpu_db_info *db_info,
+				     struct drm_file *filp)
 {
 	uint64_t index;
 	struct drm_gem_object *gobj;
-	struct amdgpu_userq_obj *db_obj = &queue->db_obj;
-	int r;
+	struct amdgpu_userq_obj *db_obj = db_info->db_obj;
+	int r, db_size;
 
-	gobj = drm_gem_object_lookup(filp, queue->doorbell_handle);
+	gobj = drm_gem_object_lookup(filp, db_info->doorbell_handle);
 	if (gobj == NULL) {
 		DRM_ERROR("Can't find GEM object for doorbell\n");
 		return -EINVAL;
@@ -222,8 +221,9 @@ amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
 		goto unpin_bo;
 	}
 
+	db_size = sizeof(u64);
 	index = amdgpu_doorbell_index_on_bar(uq_mgr->adev, db_obj->obj,
-					     doorbell_offset, sizeof(u64));
+					     db_info->doorbell_offset, db_size);
 	DRM_DEBUG_DRIVER("[Usermode queues] doorbell index=%lld\n", index);
 	amdgpu_bo_unreserve(db_obj->obj);
 	return index;
@@ -268,6 +268,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	struct amdgpu_device *adev = uq_mgr->adev;
 	const struct amdgpu_userq_funcs *uq_funcs;
 	struct amdgpu_usermode_queue *queue;
+	struct amdgpu_db_info db_info;
 	uint64_t index;
 	int qid, r = 0;
 
@@ -302,19 +303,23 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 		goto unlock;
 	}
 	queue->doorbell_handle = args->in.doorbell_handle;
-	queue->doorbell_index = args->in.doorbell_offset;
 	queue->queue_type = args->in.ip_type;
 	queue->vm = &fpriv->vm;
 
+	db_info.queue_type = queue->queue_type;
+	db_info.doorbell_handle = queue->doorbell_handle;
+	db_info.db_obj = &queue->db_obj;
+	db_info.doorbell_offset = args->in.doorbell_offset;
+
 	/* Convert relative doorbell offset into absolute doorbell index */
-	index = amdgpu_userqueue_get_doorbell_index(uq_mgr, queue, filp, args->in.doorbell_offset);
+	index = amdgpu_userqueue_get_doorbell_index(uq_mgr, &db_info, filp);
 	if (index == (uint64_t)-EINVAL) {
 		DRM_ERROR("Failed to get doorbell for queue\n");
 		kfree(queue);
 		goto unlock;
 	}
-	queue->doorbell_index = index;
 
+	queue->doorbell_index = index;
 	xa_init_flags(&queue->fence_drv_xa, XA_FLAGS_ALLOC);
 	r = amdgpu_userq_fence_driver_alloc(adev, queue);
 	if (r) {
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +5 -0
index 1109144ed7e0..34b4a7eb79ac 100644
@@ -105,4 +105,9 @@ int amdgpu_userqueue_active(struct amdgpu_userq_mgr *uq_mgr);
 
 void amdgpu_userqueue_ensure_ev_fence(struct amdgpu_userq_mgr *userq_mgr,
 				      struct amdgpu_eviction_fence_mgr *evf_mgr);
+
+uint64_t amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
+				     struct amdgpu_db_info *db_info,
+				     struct drm_file *filp);
+
 #endif
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH 2/3] drm/amdgpu: map doorbell for the requested userq

Quoted 7 lines · Saleemkhan Jamadar

Made changes to the doorbell mapping func more generic, by taking parameters that vary based on IPs and/or usecase into db_info structure.

]

This line above is garbage, please make sure that you pass checkpatch.pl for all the patches in this series.

Quoted 35 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 27 +++++++++++--------
  .../gpu/drm/amd/include/amdgpu_userqueue.h    |  5 ++++
  2 files changed, 21 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +6 -7
index 85baba323ba5..769154223e2d 100644
@@ -189,18 +189,17 @@ void amdgpu_userqueue_destroy_object(struct amdgpu_userq_mgr *uq_mgr,
  	amdgpu_bo_unref(&userq_obj->obj);
  }
 
-static uint64_t
+uint64_t
  amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
-				     struct amdgpu_usermode_queue *queue,
-				     struct drm_file *filp,
-				     uint32_t doorbell_offset)
+				     struct amdgpu_db_info *db_info,
+				     struct drm_file *filp)
  {
  	uint64_t index;
  	struct drm_gem_object *gobj;
-	struct amdgpu_userq_obj *db_obj = &queue->db_obj;
-	int r;
+	struct amdgpu_userq_obj *db_obj = db_info->db_obj;
+	int r, db_size;
 
-	gobj = drm_gem_object_lookup(filp, queue->doorbell_handle);
+	gobj = drm_gem_object_lookup(filp, db_info->doorbell_handle);
  	if (gobj == NULL) {
  		DRM_ERROR("Can't find GEM object for doorbell\n");
  		return -EINVAL;

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr, · line 224

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -0
@@ -222,8 +221,9 @@ amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
  		goto unpin_bo;
  	}
 
+	db_size = sizeof(u64);

may be move this line into next patch (and, where we are overwriting this for other IPs.

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr, · line 226

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -1
  	index = amdgpu_doorbell_index_on_bar(uq_mgr->adev, db_obj->obj,
-					     doorbell_offset, sizeof(u64));
+					     db_info->doorbell_offset, db_size);

Same for this line, pls move this to next patch.

Quoted 43 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +8 -3
  	DRM_DEBUG_DRIVER("[Usermode queues] doorbell index=%lld\n", index);
  	amdgpu_bo_unreserve(db_obj->obj);
  	return index;
@@ -268,6 +268,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  	struct amdgpu_device *adev = uq_mgr->adev;
  	const struct amdgpu_userq_funcs *uq_funcs;
  	struct amdgpu_usermode_queue *queue;
+	struct amdgpu_db_info db_info;
  	uint64_t index;
  	int qid, r = 0;
 
@@ -302,19 +303,23 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  		goto unlock;
  	}
  	queue->doorbell_handle = args->in.doorbell_handle;
-	queue->doorbell_index = args->in.doorbell_offset;
  	queue->queue_type = args->in.ip_type;
  	queue->vm = &fpriv->vm;
 
+	db_info.queue_type = queue->queue_type;
+	db_info.doorbell_handle = queue->doorbell_handle;
+	db_info.db_obj = &queue->db_obj;
+	db_info.doorbell_offset = args->in.doorbell_offset;
+
  	/* Convert relative doorbell offset into absolute doorbell index */
-	index = amdgpu_userqueue_get_doorbell_index(uq_mgr, queue, filp, args->in.doorbell_offset);
+	index = amdgpu_userqueue_get_doorbell_index(uq_mgr, &db_info, filp);
  	if (index == (uint64_t)-EINVAL) {
  		DRM_ERROR("Failed to get doorbell for queue\n");
  		kfree(queue);
  		goto unlock;
  	}
-	queue->doorbell_index = index;
 
+	queue->doorbell_index = index;
  	xa_init_flags(&queue->fence_drv_xa, XA_FLAGS_ALLOC);
  	r = amdgpu_userq_fence_driver_alloc(adev, queue);
  	if (r) {
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +0 -0
index 1109144ed7e0..34b4a7eb79ac 100644

drivers/gpu/drm/amd/include/amdgpu_userqueue.h int amdgpu_userqueue_active(struct amdgpu_userq_mgr *uq_mgr); · line 111

Quoted 7 lines
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +4 -0
@@ -105,4 +105,9 @@ int amdgpu_userqueue_active(struct amdgpu_userq_mgr *uq_mgr);
 
  void amdgpu_userqueue_ensure_ev_fence(struct amdgpu_userq_mgr *userq_mgr,
  				      struct amdgpu_eviction_fence_mgr *evf_mgr);
+
+uint64_t amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
+				     struct amdgpu_db_info *db_info,
+				     struct drm_file *filp);

please fix the alignment with the '(' above. checkpatch will get this one as well.

- Shashank

Quoted 2 lines
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +1 -0
+
  #endif
#5 lore raw

PATCH 3/3 drm/amdgpu: add db size and offset range for VCN and VPE

In reply to Saleemkhan Jamadar

VCN and VPE have different offset range, update the doorbell offset range repsectively.
Doorbell size for VCN and VPE is 32bit.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +15 -0
index 769154223e2d..8c9a2f42116c 100644
@@ -222,6 +222,21 @@ amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
 	}
 
 	db_size = sizeof(u64);
+	switch (db_info->queue_type) {
+		case AMDGPU_HW_IP_VCN_ENC:
+			db_size = sizeof(u32);
+			db_info->doorbell_offset += AMDGPU_NAVI10_DOORBELL64_VCN0_1 << 1;
+		break;
+
+		case AMDGPU_HW_IP_VPE:
+			db_size = sizeof(u32);
+			db_info->doorbell_offset += AMDGPU_NAVI10_DOORBELL64_VPE << 1;
+		break;
+
+		default:
+			/* FixMe : handle this after userqs are enabled for suported IPs */
+	}
+
 	index = amdgpu_doorbell_index_on_bar(uq_mgr->adev, db_obj->obj,
 					     db_info->doorbell_offset, db_size);
 	DRM_DEBUG_DRIVER("[Usermode queues] doorbell index=%lld\n", index);
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH 3/3] drm/amdgpu: add db size and offset range for VCN and VPE

Quoted 14 lines · Saleemkhan Jamadar

VCN and VPE have different offset range, update the doorbell offset range repsectively.
Doorbell size for VCN and VPE is 32bit.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 15 +++++++++++++++
  1 file changed, 15 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0 -0
index 769154223e2d..8c9a2f42116c 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr, · line 229

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +5 -0
@@ -222,6 +222,21 @@ amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
  	}
 
  	db_size = sizeof(u64);
+	switch (db_info->queue_type) {
+		case AMDGPU_HW_IP_VCN_ENC:
+			db_size = sizeof(u32);
+			db_info->doorbell_offset += AMDGPU_NAVI10_DOORBELL64_VCN0_1 << 1;
+		break;

Please check on alignment with switch(case), checkpatch will get this one as well.

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr, · line 237

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +8 -0
+
+		case AMDGPU_HW_IP_VPE:
+			db_size = sizeof(u32);
+			db_info->doorbell_offset += AMDGPU_NAVI10_DOORBELL64_VPE << 1;
+		break;
+
+		default:
+			/* FixMe : handle this after userqs are enabled for suported IPs */

Now I think you can add cases for GFX and SDMA IPs as well, set size to U64 and then return -EINVAL in case of IP not recognized (default).

- Shashank

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +2 -0
+	}
+
  	index = amdgpu_doorbell_index_on_bar(uq_mgr->adev, db_obj->obj,
  					     db_info->doorbell_offset, db_size);
  	DRM_DEBUG_DRIVER("[Usermode queues] doorbell index=%lld\n", index);