drm/amdgpu/vcn: identify unified queue in sw init
Subsystems (2)
PATCH 1/2 drm/amdgpu/vcn: identify unified queue in sw init
From: Boyuan Zhang <[email protected]>
Determine whether VCN using unified queue in sw_init, instead of calling functions later on.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 39 ++++++++++--------------- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h | 1 + 2 files changed, 16 insertions(+), 24 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +15 -24
@@ -139,6 +139,10 @@ int amdgpu_vcn_sw_init(struct amdgpu_device *adev) } } +/* from vcn4 and above, only unified queue is used */ + adev->vcn.using_unified_queue = +amdgpu_ip_version (adev,UVD_HWIP ,0 ) >=IP_VERSION (4 ,0 ,0 ) ? true : false; + hdr = (const struct common_firmware_header *)adev->vcn.fw->data; adev->vcn.fw_version =le32_to_cpu (hdr->ucode_version);
@@ -266,18 +270,6 @@ int amdgpu_vcn_sw_fini(struct amdgpu_device *adev)return 0 ; } -/* from vcn4 and above, only unified queue is used */ -static bool amdgpu_vcn_using_unified_queue (struct amdgpu_ring *ring) -{ -struct amdgpu_device *adev = ring->adev; -bool ret = false; - -if (amdgpu_ip_version (adev,UVD_HWIP ,0 ) >=IP_VERSION (4 ,0 ,0 )) - ret = true; - -return ret; -} -bool amdgpu_vcn_is_disabled_vcn (struct amdgpu_device *adev,enum vcn_ring_type type,uint32_t vcn_instance) {bool ret = false;
@@ -747,12 +739,11 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,struct amdgpu_job *job;struct amdgpu_ib *ib;uint64_t addr =AMDGPU_GPU_PAGE_ALIGN (ib_msg->gpu_addr); -bool sq =amdgpu_vcn_using_unified_queue (ring);uint32_t *ib_checksum;uint32_t ib_pack_in_dw;int i, r; -if (sq) +if (adev->vcn.using_unified_queue) ib_size_dw +=8 ; r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL,
@@ -765,7 +756,7 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring, ib->length_dw =0 ;/* single queue headers */ -if (sq) { +if (adev->vcn.using_unified_queue) { ib_pack_in_dw =sizeof (struct amdgpu_vcn_decode_buffer ) /sizeof (uint32_t ) +4 +2 ;/* engine info + decoding ib in dw */ ib_checksum =amdgpu_vcn_unified_ring_ib_header (ib, ib_pack_in_dw, false);
@@ -784,7 +775,7 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,for (i = ib->length_dw; i < ib_size_dw; ++i) ib->ptr[i] =0x0 ; -if (sq) +if (adev->vcn.using_unified_queue)amdgpu_vcn_unified_ring_ib_checksum (&ib_checksum, ib_pack_in_dw); r =amdgpu_job_submit_direct (job, ring, &f);
@@ -874,15 +865,15 @@ static int amdgpu_vcn_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t hand struct dma_fence **fence) {unsigned int ib_size_dw =16 ; +struct amdgpu_device *adev = ring->adev;struct amdgpu_job *job;struct amdgpu_ib *ib;struct dma_fence *f =NULL ;uint32_t *ib_checksum =NULL ;uint64_t addr; -bool sq =amdgpu_vcn_using_unified_queue (ring);int i, r; -if (sq) +if (adev->vcn.using_unified_queue) ib_size_dw +=8 ; r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL,
@@ -896,7 +887,7 @@ static int amdgpu_vcn_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t hand ib->length_dw =0 ; -if (sq) +if (adev->vcn.using_unified_queue) ib_checksum =amdgpu_vcn_unified_ring_ib_header (ib,0x11 , true); ib->ptr[ib->length_dw++] =0x00000018 ;
@@ -918,7 +909,7 @@ static int amdgpu_vcn_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t handfor (i = ib->length_dw; i < ib_size_dw; ++i) ib->ptr[i] =0x0 ; -if (sq) +if (adev->vcn.using_unified_queue)amdgpu_vcn_unified_ring_ib_checksum (&ib_checksum,0x11 ); r =amdgpu_job_submit_direct (job, ring, &f);
@@ -941,15 +932,15 @@ static int amdgpu_vcn_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t han struct dma_fence **fence) {unsigned int ib_size_dw =16 ; +struct amdgpu_device *adev = ring->adev;struct amdgpu_job *job;struct amdgpu_ib *ib;struct dma_fence *f =NULL ;uint32_t *ib_checksum =NULL ;uint64_t addr; -bool sq =amdgpu_vcn_using_unified_queue (ring);int i, r; -if (sq) +if (adev->vcn.using_unified_queue) ib_size_dw +=8 ; r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL,
@@ -963,7 +954,7 @@ static int amdgpu_vcn_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t han ib->length_dw =0 ; -if (sq) +if (adev->vcn.using_unified_queue) ib_checksum =amdgpu_vcn_unified_ring_ib_header (ib,0x11 , true); ib->ptr[ib->length_dw++] =0x00000018 ;
@@ -985,7 +976,7 @@ static int amdgpu_vcn_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t hanfor (i = ib->length_dw; i < ib_size_dw; ++i) ib->ptr[i] =0x0 ; -if (sq) +if (adev->vcn.using_unified_queue)amdgpu_vcn_unified_ring_ib_checksum (&ib_checksum,0x11 ); r =amdgpu_job_submit_direct (job, ring, &f);
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +1 -0
@@ -329,6 +329,7 @@ struct amdgpu_vcn {uint16_t inst_mask;uint8_t num_inst_per_aid; +bool using_unified_queue; };struct amdgpu_fw_shared_rb_ptrs_struct {
Signature · 1 line
2.34.1
PATCH 2/2 drm/amdgpu/vcn: not pause dpg for unified queue
From: Boyuan Zhang <[email protected]>
For unified queue, DPG pause for encoding is done inside VCN firmware, so there is no need to pause dpg based on ring type in kernel.
For previous generations, pausing DPG for encoding in kernel is still needed.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +8 -3
@@ -412,7 +412,8 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work)for (i =0 ; i < adev->vcn.num_enc_rings; ++i) fence[j] +=amdgpu_fence_count_emitted (&adev->vcn.inst[j].ring_enc[i]); -if (adev->pg_flags &AMD_PG_SUPPORT_VCN_DPG ) { +if (adev->pg_flags &AMD_PG_SUPPORT_VCN_DPG && + !adev->vcn.using_unified_queue) {struct dpg_pause_state new_state; if (fence[j] ||
@@ -458,7 +459,8 @@ void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)amdgpu_device_ip_set_powergating_state (adev,AMD_IP_BLOCK_TYPE_VCN ,AMD_PG_STATE_UNGATE ); -if (adev->pg_flags &AMD_PG_SUPPORT_VCN_DPG ) { +if (adev->pg_flags &AMD_PG_SUPPORT_VCN_DPG && + !adev->vcn.using_unified_queue) {struct dpg_pause_state new_state;if (ring->funcs->type ==AMDGPU_RING_TYPE_VCN_ENC ) {
@@ -484,8 +486,11 @@ void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)void amdgpu_vcn_ring_end_use (struct amdgpu_ring *ring) { +struct amdgpu_device *adev = ring->adev; +if (ring->adev->pg_flags &AMD_PG_SUPPORT_VCN_DPG && - ring->funcs->type ==AMDGPU_RING_TYPE_VCN_ENC ) + ring->funcs->type ==AMDGPU_RING_TYPE_VCN_ENC && + !adev->vcn.using_unified_queue)atomic_dec (&ring->adev->vcn.inst[ring->me].dpg_enc_submission_cnt);atomic_dec (&ring->adev->vcn.total_submission_cnt);
Signature · 1 line
2.34.1
Quoted 17 lines · On Wed, Jul 10, 2024 at 2:10 PM <[email protected]> wrote:
From: Boyuan Zhang <[email protected]>
Determine whether VCN using unified queue in
sw_init, instead of calling functions later on.Signed-off-by Boyuan Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 39 ++++++++++--------------- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h | 1 + 2 files changed, 16 insertions(+), 24 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c int amdgpu_vcn_sw_init(struct amdgpu_device *adev) · line 144
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3
-0@@ -139,6 +139,10 @@ int amdgpu_vcn_sw_init(struct amdgpu_device *adev) } } +/* from vcn4 and above, only unified queue is used */ + adev->vcn.using_unified_queue = +amdgpu_ip_version (adev,UVD_HWIP ,0 ) >=IP_VERSION (4 ,0 ,0 ) ? true : false;
You can drop the "? true : false" part. A lot of static checkers will complain about that as it's not necessary.
With that fixed, the series is:
Quoted 142 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +12
-24+ hdr = (const struct common_firmware_header *)adev->vcn.fw->data; adev->vcn.fw_version =le32_to_cpu (hdr->ucode_version);@@ -266,18 +270,6 @@ int amdgpu_vcn_sw_fini(struct amdgpu_device *adev)return 0 ; } -/* from vcn4 and above, only unified queue is used */ -static bool amdgpu_vcn_using_unified_queue (struct amdgpu_ring *ring) -{ -struct amdgpu_device *adev = ring->adev; -bool ret = false; - -if (amdgpu_ip_version (adev,UVD_HWIP ,0 ) >=IP_VERSION (4 ,0 ,0 )) - ret = true; - -return ret; -} -bool amdgpu_vcn_is_disabled_vcn (struct amdgpu_device *adev,enum vcn_ring_type type,uint32_t vcn_instance) {bool ret = false;@@ -747,12 +739,11 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,struct amdgpu_job *job;struct amdgpu_ib *ib;uint64_t addr =AMDGPU_GPU_PAGE_ALIGN (ib_msg->gpu_addr); -bool sq =amdgpu_vcn_using_unified_queue (ring);uint32_t *ib_checksum;uint32_t ib_pack_in_dw;int i, r; -if (sq) +if (adev->vcn.using_unified_queue) ib_size_dw +=8 ; r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL,@@ -765,7 +756,7 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring, ib->length_dw =0 ;/* single queue headers */ -if (sq) { +if (adev->vcn.using_unified_queue) { ib_pack_in_dw =sizeof (struct amdgpu_vcn_decode_buffer ) /sizeof (uint32_t ) +4 +2 ;/* engine info + decoding ib in dw */ ib_checksum =amdgpu_vcn_unified_ring_ib_header (ib, ib_pack_in_dw, false);@@ -784,7 +775,7 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,for (i = ib->length_dw; i < ib_size_dw; ++i) ib->ptr[i] =0x0 ; -if (sq) +if (adev->vcn.using_unified_queue)amdgpu_vcn_unified_ring_ib_checksum (&ib_checksum, ib_pack_in_dw); r =amdgpu_job_submit_direct (job, ring, &f);@@ -874,15 +865,15 @@ static int amdgpu_vcn_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t hand struct dma_fence **fence) {unsigned int ib_size_dw =16 ; +struct amdgpu_device *adev = ring->adev;struct amdgpu_job *job;struct amdgpu_ib *ib;struct dma_fence *f =NULL ;uint32_t *ib_checksum =NULL ;uint64_t addr; -bool sq =amdgpu_vcn_using_unified_queue (ring);int i, r; -if (sq) +if (adev->vcn.using_unified_queue) ib_size_dw +=8 ; r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL,@@ -896,7 +887,7 @@ static int amdgpu_vcn_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t hand ib->length_dw =0 ; -if (sq) +if (adev->vcn.using_unified_queue) ib_checksum =amdgpu_vcn_unified_ring_ib_header (ib,0x11 , true); ib->ptr[ib->length_dw++] =0x00000018 ;@@ -918,7 +909,7 @@ static int amdgpu_vcn_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t handfor (i = ib->length_dw; i < ib_size_dw; ++i) ib->ptr[i] =0x0 ; -if (sq) +if (adev->vcn.using_unified_queue)amdgpu_vcn_unified_ring_ib_checksum (&ib_checksum,0x11 ); r =amdgpu_job_submit_direct (job, ring, &f);@@ -941,15 +932,15 @@ static int amdgpu_vcn_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t han struct dma_fence **fence) {unsigned int ib_size_dw =16 ; +struct amdgpu_device *adev = ring->adev;struct amdgpu_job *job;struct amdgpu_ib *ib;struct dma_fence *f =NULL ;uint32_t *ib_checksum =NULL ;uint64_t addr; -bool sq =amdgpu_vcn_using_unified_queue (ring);int i, r; -if (sq) +if (adev->vcn.using_unified_queue) ib_size_dw +=8 ; r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL,@@ -963,7 +954,7 @@ static int amdgpu_vcn_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t han ib->length_dw =0 ; -if (sq) +if (adev->vcn.using_unified_queue) ib_checksum =amdgpu_vcn_unified_ring_ib_header (ib,0x11 , true); ib->ptr[ib->length_dw++] =0x00000018 ;@@ -985,7 +976,7 @@ static int amdgpu_vcn_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t hanfor (i = ib->length_dw; i < ib_size_dw; ++i) ib->ptr[i] =0x0 ; -if (sq) +if (adev->vcn.using_unified_queue)amdgpu_vcn_unified_ring_ib_checksum (&ib_checksum,0x11 ); r =amdgpu_job_submit_direct (job, ring, &f);drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +1
-1@@ -329,6 +329,7 @@ struct amdgpu_vcn {uint16_t inst_mask;uint8_t num_inst_per_aid; +bool using_unified_queue; };struct amdgpu_fw_shared_rb_ptrs_struct { --2.34.1