Re: [PATCH 3/7] drm/amdgpu/vcn: sriov support for vcn_v4_0_3
On 7/21/2023 12:49 AM, Samir Dhume wrote: initialization table handshake with mmsch Signed-off-by: Samir Dhume --- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 261 +--- 1 file changed, 237 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c index 411c1d802823..8650e3c6288d 100644 --- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c @@ -31,6 +31,7 @@ #include "soc15d.h" #include "soc15_hw_ip.h" #include "vcn_v2_0.h" +#include "mmsch_v4_0_3.h" #include "vcn/vcn_4_0_3_offset.h" #include "vcn/vcn_4_0_3_sh_mask.h" @@ -44,6 +45,7 @@ #define VCN_VID_SOC_ADDRESS_2_0 0x1fb00 #define VCN1_VID_SOC_ADDRESS_3_0 0x48300 +static int vcn_v4_0_3_start_sriov(struct amdgpu_device *adev); static void vcn_v4_0_3_set_unified_ring_funcs(struct amdgpu_device *adev); static void vcn_v4_0_3_set_irq_funcs(struct amdgpu_device *adev); static int vcn_v4_0_3_set_powergating_state(void *handle, @@ -130,6 +132,10 @@ static int vcn_v4_0_3_sw_init(void *handle) amdgpu_vcn_fwlog_init(>vcn.inst[i]); } + r = amdgpu_virt_alloc_mm_table(adev); + if (r) + return r; + if (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) adev->vcn.pause_dpg_mode = vcn_v4_0_3_pause_dpg_mode; @@ -167,6 +173,8 @@ static int vcn_v4_0_3_sw_fini(void *handle) drm_dev_exit(idx); } + amdgpu_virt_free_mm_table(adev); + r = amdgpu_vcn_suspend(adev); if (r) return r; @@ -189,33 +197,50 @@ static int vcn_v4_0_3_hw_init(void *handle) struct amdgpu_ring *ring; int i, r, vcn_inst; - for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { - vcn_inst = GET_INST(VCN, i); - ring = >vcn.inst[i].ring_enc[0]; + if (amdgpu_sriov_vf(adev)) { + r = vcn_v4_0_3_start_sriov(adev); + if (r) + goto done; + + for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { + if (adev->vcn.harvest_config & (1 << i)) + continue; In vcn v4.0.3 we have adev->vcn.num_vcn_inst as the actual number of vcn instances present and not the max possible number. Better to follow the same style 'vcn_inst = GET_INST(VCN, i)' for sriov mapping also. Any harvest mapping info is expected to be adjusted during initial parsing of IP instance discovery table. - if (ring->use_doorbell) { - adev->nbio.funcs->vcn_doorbell_range( - adev, ring->use_doorbell, - (adev->doorbell_index.vcn.vcn_ring0_1 << 1) + - 9 * vcn_inst, - adev->vcn.inst[i].aid_id); - - WREG32_SOC15( - VCN, GET_INST(VCN, ring->me), - regVCN_RB1_DB_CTRL, - ring->doorbell_index - << VCN_RB1_DB_CTRL__OFFSET__SHIFT | - VCN_RB1_DB_CTRL__EN_MASK); - - /* Read DB_CTRL to flush the write DB_CTRL command. */ - RREG32_SOC15( - VCN, GET_INST(VCN, ring->me), - regVCN_RB1_DB_CTRL); + ring = >vcn.inst[i].ring_enc[0]; + ring->wptr = 0; + ring->wptr_old = 0; + vcn_v4_0_3_unified_ring_set_wptr(ring); + ring->sched.ready = true; } + } else { + for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { + vcn_inst = GET_INST(VCN, i); + ring = >vcn.inst[i].ring_enc[0]; + + if (ring->use_doorbell) { + adev->nbio.funcs->vcn_doorbell_range( + adev, ring->use_doorbell, + (adev->doorbell_index.vcn.vcn_ring0_1 << 1) + + 9 * vcn_inst, + adev->vcn.inst[i].aid_id); + + WREG32_SOC15( + VCN, GET_INST(VCN, ring->me), + regVCN_RB1_DB_CTRL, + ring->doorbell_index + << VCN_RB1_DB_CTRL__OFFSET__SHIFT | + VCN_RB1_DB_CTRL__EN_MASK); + + /* Read DB_CTRL to flush the write DB_CTRL command. */ + RREG32_SOC15( + VCN, GET_INST(VCN, ring->me), +
RE: [PATCH 3/7] drm/amdgpu/vcn: sriov support for vcn_v4_0_3
[Public] Fair point. I'll follow up with another patch. Thanks, Samir -Original Message- From: Chen, Guchun Sent: Tuesday, July 18, 2023 1:54 AM To: Dhume, Samir ; amd-gfx@lists.freedesktop.org Cc: Dhume, Samir Subject: RE: [PATCH 3/7] drm/amdgpu/vcn: sriov support for vcn_v4_0_3 [Public] > -Original Message- > From: amd-gfx On Behalf Of > Samir Dhume > Sent: Monday, July 17, 2023 11:59 PM > To: amd-gfx@lists.freedesktop.org > Cc: Dhume, Samir > Subject: [PATCH 3/7] drm/amdgpu/vcn: sriov support for vcn_v4_0_3 > > initialization table handshake with mmsch > > Signed-off-by: Samir Dhume > --- > drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 264 > +--- > 1 file changed, 240 insertions(+), 24 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c > b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c > index 411c1d802823..ac405dfcfaf1 100644 > --- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c > +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c > @@ -31,6 +31,7 @@ > #include "soc15d.h" > #include "soc15_hw_ip.h" > #include "vcn_v2_0.h" > +#include "mmsch_v4_0_3.h" > > #include "vcn/vcn_4_0_3_offset.h" > #include "vcn/vcn_4_0_3_sh_mask.h" > @@ -44,6 +45,7 @@ > #define VCN_VID_SOC_ADDRESS_2_0 0x1fb00 > #define VCN1_VID_SOC_ADDRESS_3_0 0x48300 > > +static int vcn_v4_0_3_start_sriov(struct amdgpu_device *adev); > static void vcn_v4_0_3_set_unified_ring_funcs(struct amdgpu_device > *adev); static void vcn_v4_0_3_set_irq_funcs(struct amdgpu_device > *adev); static int vcn_v4_0_3_set_powergating_state(void *handle, @@ > -130,6 +132,12 @@ static int vcn_v4_0_3_sw_init(void *handle) > amdgpu_vcn_fwlog_init(>vcn.inst[i]); > } > > + if (amdgpu_sriov_vf(adev)) { > + r = amdgpu_virt_alloc_mm_table(adev); amdgpu_virt_alloc_mm_table has an early check of amdgpu_sriov_vf(adev), so from coding style's perspective, I think you can drop this superfluous check here and directly call amdgpu_virt_alloc_mm_table. > + if (r) > + return r; > + } > + > if (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) > adev->vcn.pause_dpg_mode = vcn_v4_0_3_pause_dpg_mode; > > @@ -167,6 +175,9 @@ static int vcn_v4_0_3_sw_fini(void *handle) > drm_dev_exit(idx); > } > > + if (amdgpu_sriov_vf(adev)) > + amdgpu_virt_free_mm_table(adev); Same as above. Regards, Guchun > r = amdgpu_vcn_suspend(adev); > if (r) > return r; > @@ -189,33 +200,50 @@ static int vcn_v4_0_3_hw_init(void *handle) > struct amdgpu_ring *ring; > int i, r, vcn_inst; > > - for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { > - vcn_inst = GET_INST(VCN, i); > - ring = >vcn.inst[i].ring_enc[0]; > + if (amdgpu_sriov_vf(adev)) { > + r = vcn_v4_0_3_start_sriov(adev); > + if (r) > + goto done; > > - if (ring->use_doorbell) { > - adev->nbio.funcs->vcn_doorbell_range( > - adev, ring->use_doorbell, > - (adev->doorbell_index.vcn.vcn_ring0_1 << 1) > + > - 9 * vcn_inst, > - adev->vcn.inst[i].aid_id); > - > - WREG32_SOC15( > - VCN, GET_INST(VCN, ring->me), > - regVCN_RB1_DB_CTRL, > - ring->doorbell_index > - << > VCN_RB1_DB_CTRL__OFFSET__SHIFT | > - VCN_RB1_DB_CTRL__EN_MASK); > - > - /* Read DB_CTRL to flush the write DB_CTRL > command. */ > - RREG32_SOC15( > - VCN, GET_INST(VCN, ring->me), > - regVCN_RB1_DB_CTRL); > + for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { > + if (adev->vcn.harvest_config & (1 << i)) > + continue; > + > + ring = >vcn.inst[i].ring_enc[0]; > + ring->wptr = 0; > + ring->wptr_old = 0; > + vcn_v4_0_3_unified_ring_set_wptr(ring); > + ring->sched.ready = true; > } > + } else { > + for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { > + vcn_inst = GET_INS
RE: [PATCH 3/7] drm/amdgpu/vcn: sriov support for vcn_v4_0_3
[Public] > -Original Message- > From: amd-gfx On Behalf Of > Samir Dhume > Sent: Monday, July 17, 2023 11:59 PM > To: amd-gfx@lists.freedesktop.org > Cc: Dhume, Samir > Subject: [PATCH 3/7] drm/amdgpu/vcn: sriov support for vcn_v4_0_3 > > initialization table handshake with mmsch > > Signed-off-by: Samir Dhume > --- > drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 264 > +--- > 1 file changed, 240 insertions(+), 24 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c > b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c > index 411c1d802823..ac405dfcfaf1 100644 > --- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c > +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c > @@ -31,6 +31,7 @@ > #include "soc15d.h" > #include "soc15_hw_ip.h" > #include "vcn_v2_0.h" > +#include "mmsch_v4_0_3.h" > > #include "vcn/vcn_4_0_3_offset.h" > #include "vcn/vcn_4_0_3_sh_mask.h" > @@ -44,6 +45,7 @@ > #define VCN_VID_SOC_ADDRESS_2_0 0x1fb00 > #define VCN1_VID_SOC_ADDRESS_3_0 0x48300 > > +static int vcn_v4_0_3_start_sriov(struct amdgpu_device *adev); > static void vcn_v4_0_3_set_unified_ring_funcs(struct amdgpu_device *adev); > static void vcn_v4_0_3_set_irq_funcs(struct amdgpu_device *adev); static > int vcn_v4_0_3_set_powergating_state(void *handle, @@ -130,6 +132,12 > @@ static int vcn_v4_0_3_sw_init(void *handle) > amdgpu_vcn_fwlog_init(>vcn.inst[i]); > } > > + if (amdgpu_sriov_vf(adev)) { > + r = amdgpu_virt_alloc_mm_table(adev); amdgpu_virt_alloc_mm_table has an early check of amdgpu_sriov_vf(adev), so from coding style's perspective, I think you can drop this superfluous check here and directly call amdgpu_virt_alloc_mm_table. > + if (r) > + return r; > + } > + > if (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) > adev->vcn.pause_dpg_mode = > vcn_v4_0_3_pause_dpg_mode; > > @@ -167,6 +175,9 @@ static int vcn_v4_0_3_sw_fini(void *handle) > drm_dev_exit(idx); > } > > + if (amdgpu_sriov_vf(adev)) > + amdgpu_virt_free_mm_table(adev); Same as above. Regards, Guchun > r = amdgpu_vcn_suspend(adev); > if (r) > return r; > @@ -189,33 +200,50 @@ static int vcn_v4_0_3_hw_init(void *handle) > struct amdgpu_ring *ring; > int i, r, vcn_inst; > > - for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { > - vcn_inst = GET_INST(VCN, i); > - ring = >vcn.inst[i].ring_enc[0]; > + if (amdgpu_sriov_vf(adev)) { > + r = vcn_v4_0_3_start_sriov(adev); > + if (r) > + goto done; > > - if (ring->use_doorbell) { > - adev->nbio.funcs->vcn_doorbell_range( > - adev, ring->use_doorbell, > - (adev->doorbell_index.vcn.vcn_ring0_1 << 1) > + > - 9 * vcn_inst, > - adev->vcn.inst[i].aid_id); > - > - WREG32_SOC15( > - VCN, GET_INST(VCN, ring->me), > - regVCN_RB1_DB_CTRL, > - ring->doorbell_index > - << > VCN_RB1_DB_CTRL__OFFSET__SHIFT | > - VCN_RB1_DB_CTRL__EN_MASK); > - > - /* Read DB_CTRL to flush the write DB_CTRL > command. */ > - RREG32_SOC15( > - VCN, GET_INST(VCN, ring->me), > - regVCN_RB1_DB_CTRL); > + for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { > + if (adev->vcn.harvest_config & (1 << i)) > + continue; > + > + ring = >vcn.inst[i].ring_enc[0]; > + ring->wptr = 0; > + ring->wptr_old = 0; > + vcn_v4_0_3_unified_ring_set_wptr(ring); > + ring->sched.ready = true; > } > + } else { > + for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { > + vcn_inst = GET_INST(VCN, i); > + ring = >vcn.inst[i].ring_enc[0]; > + > + if (ring->use_doorbell) { > + adev->nbio.funcs->vcn_doorbell_range( > + adev, ring->use_doorbell, > + (adev- > >doorbell_index.vcn.vcn_ring0_1 << 1) + > + 9 * vcn_inst, > + adev->vcn.inst[i].aid_id); > + > + WREG32_SOC15( > + VCN, GET_INST(VCN, ring->me), > + regVCN_RB1_DB_CTRL, > + ring->doorbell_index > + << >