Allocate and map doorbell based on requests
Subsystems (2)
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
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
@@ -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
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.
Signed-off-by Saleemkhan Jamadar <[email protected]>--- drivers/gpu/drm/amd/include/amdgpu_userqueue.h | 7 +++++++ 1 file changed, 7 insertions(+)drivers/gpu/drm/amd/include/amdgpu_userqueue.h +0
-0
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
-0int 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);
PATCH 2/3 drm/amdgpu: map doorbell for the requested userq
In reply to Saleemkhan JamadarMade 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
@@ -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
@@ -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
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_infostructure.Signed-off-by Saleemkhan Jamadar <[email protected]>]
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@@ -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
-1index =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
-3DRM_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
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
PATCH 3/3 drm/amdgpu: add db size and offset range for VCN and VPE
In reply to Saleemkhan JamadarVCN 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
@@ -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
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.Signed-off-by Saleemkhan Jamadar<[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0
-0
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);