On Thu, Oct 24, 2024 at 11:58 PM <boyuan.zhang@xxxxxxx> wrote: > > From: Boyuan Zhang <boyuan.zhang@xxxxxxx> > > Pass instance parameter to amdgpu_vcn_sw_init(), and perform > sw init ONLY for the given vcn instance, instead of for all > vcn instances. Modify each vcn generation accordingly. > > Signed-off-by: Boyuan Zhang <boyuan.zhang@xxxxxxx> Reviewed-by: Alex Deucher <alexander.deucher@xxxxxxx> > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 83 ++++++++++++------------- > drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h | 2 +- > drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c | 5 +- > drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 5 +- > drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 6 +- > drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 7 ++- > drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 7 ++- > drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 5 +- > drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 7 ++- > drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 7 ++- > 10 files changed, 69 insertions(+), 65 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c > index 21701738030f..2c55166e27d9 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c > @@ -111,24 +111,23 @@ int amdgpu_vcn_early_init(struct amdgpu_device *adev, int inst) > return r; > } > > -int amdgpu_vcn_sw_init(struct amdgpu_device *adev) > +int amdgpu_vcn_sw_init(struct amdgpu_device *adev, int inst) > { > unsigned long bo_size; > const struct common_firmware_header *hdr; > unsigned char fw_check; > unsigned int fw_shared_size, log_offset; > - int i, r; > + int r; > + > + adev->vcn.inst[inst].adev = adev; > + adev->vcn.inst[inst].work_inst = inst; > + INIT_DELAYED_WORK(&adev->vcn.inst[inst].idle_work, amdgpu_vcn_idle_work_handler); > > - for (i = 0; i < adev->vcn.num_vcn_inst; i++) { > - adev->vcn.inst[i].adev = adev; > - adev->vcn.inst[i].work_inst = i; > - INIT_DELAYED_WORK(&adev->vcn.inst[i].idle_work, amdgpu_vcn_idle_work_handler); > - } > mutex_init(&adev->vcn.vcn_pg_lock); > mutex_init(&adev->vcn.vcn1_jpeg1_workaround); > atomic_set(&adev->vcn.total_submission_cnt, 0); > - for (i = 0; i < adev->vcn.num_vcn_inst; i++) > - atomic_set(&adev->vcn.inst[i].dpg_enc_submission_cnt, 0); > + > + atomic_set(&adev->vcn.inst[inst].dpg_enc_submission_cnt, 0); > > if ((adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) && > (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG)) > @@ -206,45 +205,43 @@ int amdgpu_vcn_sw_init(struct amdgpu_device *adev) > if (amdgpu_vcnfw_log) > bo_size += AMDGPU_VCNFW_LOG_SIZE; > > - for (i = 0; i < adev->vcn.num_vcn_inst; i++) { > - if (adev->vcn.harvest_config & (1 << i)) > - continue; > + if (adev->vcn.harvest_config & (1 << inst)) > + return 0; > > - r = amdgpu_bo_create_kernel(adev, bo_size, PAGE_SIZE, > - AMDGPU_GEM_DOMAIN_VRAM | > - AMDGPU_GEM_DOMAIN_GTT, > - &adev->vcn.inst[i].vcpu_bo, > - &adev->vcn.inst[i].gpu_addr, > - &adev->vcn.inst[i].cpu_addr); > - if (r) { > - dev_err(adev->dev, "(%d) failed to allocate vcn bo\n", r); > - return r; > - } > + r = amdgpu_bo_create_kernel(adev, bo_size, PAGE_SIZE, > + AMDGPU_GEM_DOMAIN_VRAM | > + AMDGPU_GEM_DOMAIN_GTT, > + &adev->vcn.inst[inst].vcpu_bo, > + &adev->vcn.inst[inst].gpu_addr, > + &adev->vcn.inst[inst].cpu_addr); > + if (r) { > + dev_err(adev->dev, "(%d) failed to allocate vcn bo\n", r); > + return r; > + } > > - adev->vcn.inst[i].fw_shared.cpu_addr = adev->vcn.inst[i].cpu_addr + > - bo_size - fw_shared_size; > - adev->vcn.inst[i].fw_shared.gpu_addr = adev->vcn.inst[i].gpu_addr + > - bo_size - fw_shared_size; > + adev->vcn.inst[inst].fw_shared.cpu_addr = adev->vcn.inst[inst].cpu_addr + > + bo_size - fw_shared_size; > + adev->vcn.inst[inst].fw_shared.gpu_addr = adev->vcn.inst[inst].gpu_addr + > + bo_size - fw_shared_size; > > - adev->vcn.inst[i].fw_shared.mem_size = fw_shared_size; > + adev->vcn.inst[inst].fw_shared.mem_size = fw_shared_size; > > - if (amdgpu_vcnfw_log) { > - adev->vcn.inst[i].fw_shared.cpu_addr -= AMDGPU_VCNFW_LOG_SIZE; > - adev->vcn.inst[i].fw_shared.gpu_addr -= AMDGPU_VCNFW_LOG_SIZE; > - adev->vcn.inst[i].fw_shared.log_offset = log_offset; > - } > + if (amdgpu_vcnfw_log) { > + adev->vcn.inst[inst].fw_shared.cpu_addr -= AMDGPU_VCNFW_LOG_SIZE; > + adev->vcn.inst[inst].fw_shared.gpu_addr -= AMDGPU_VCNFW_LOG_SIZE; > + adev->vcn.inst[inst].fw_shared.log_offset = log_offset; > + } > > - if (adev->vcn.indirect_sram) { > - r = amdgpu_bo_create_kernel(adev, 64 * 2 * 4, PAGE_SIZE, > - AMDGPU_GEM_DOMAIN_VRAM | > - AMDGPU_GEM_DOMAIN_GTT, > - &adev->vcn.inst[i].dpg_sram_bo, > - &adev->vcn.inst[i].dpg_sram_gpu_addr, > - &adev->vcn.inst[i].dpg_sram_cpu_addr); > - if (r) { > - dev_err(adev->dev, "VCN %d (%d) failed to allocate DPG bo\n", i, r); > - return r; > - } > + if (adev->vcn.indirect_sram) { > + r = amdgpu_bo_create_kernel(adev, 64 * 2 * 4, PAGE_SIZE, > + AMDGPU_GEM_DOMAIN_VRAM | > + AMDGPU_GEM_DOMAIN_GTT, > + &adev->vcn.inst[inst].dpg_sram_bo, > + &adev->vcn.inst[inst].dpg_sram_gpu_addr, > + &adev->vcn.inst[inst].dpg_sram_cpu_addr); > + if (r) { > + dev_err(adev->dev, "VCN %d (%d) failed to allocate DPG bo\n", inst, r); > + return r; > } > } > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h > index 58fbb87e5ec4..4809da69bd1b 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h > @@ -484,7 +484,7 @@ enum vcn_ring_type { > }; > > int amdgpu_vcn_early_init(struct amdgpu_device *adev, int inst); > -int amdgpu_vcn_sw_init(struct amdgpu_device *adev); > +int amdgpu_vcn_sw_init(struct amdgpu_device *adev, int inst); > int amdgpu_vcn_sw_fini(struct amdgpu_device *adev); > int amdgpu_vcn_suspend(struct amdgpu_device *adev); > int amdgpu_vcn_resume(struct amdgpu_device *adev); > diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c > index 6fd509e6744d..808d69ab0904 100644 > --- a/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c > +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c > @@ -126,11 +126,12 @@ static int vcn_v1_0_early_init(struct amdgpu_ip_block *ip_block) > */ > static int vcn_v1_0_sw_init(struct amdgpu_ip_block *ip_block) > { > + struct amdgpu_device *adev = ip_block->adev; > + int inst = ip_block->instance; > struct amdgpu_ring *ring; > int i, r; > uint32_t reg_count = ARRAY_SIZE(vcn_reg_list_1_0); > uint32_t *ptr; > - struct amdgpu_device *adev = ip_block->adev; > > /* VCN DEC TRAP */ > r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_VCN, > @@ -146,7 +147,7 @@ static int vcn_v1_0_sw_init(struct amdgpu_ip_block *ip_block) > return r; > } > > - r = amdgpu_vcn_sw_init(adev); > + r = amdgpu_vcn_sw_init(adev, inst); > if (r) > return r; > > diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c > index 8f7038190a43..a86cff00d761 100644 > --- a/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c > +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c > @@ -131,11 +131,12 @@ static int vcn_v2_0_early_init(struct amdgpu_ip_block *ip_block) > */ > static int vcn_v2_0_sw_init(struct amdgpu_ip_block *ip_block) > { > + struct amdgpu_device *adev = ip_block->adev; > + int inst = ip_block->instance; > struct amdgpu_ring *ring; > int i, r; > uint32_t reg_count = ARRAY_SIZE(vcn_reg_list_2_0); > uint32_t *ptr; > - struct amdgpu_device *adev = ip_block->adev; > volatile struct amdgpu_fw_shared *fw_shared; > > /* VCN DEC TRAP */ > @@ -154,7 +155,7 @@ static int vcn_v2_0_sw_init(struct amdgpu_ip_block *ip_block) > return r; > } > > - r = amdgpu_vcn_sw_init(adev); > + r = amdgpu_vcn_sw_init(adev, inst); > if (r) > return r; > > diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c > index 74814370ddc9..9967ac3fc51b 100644 > --- a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c > +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c > @@ -156,12 +156,12 @@ static int vcn_v2_5_early_init(struct amdgpu_ip_block *ip_block) > */ > static int vcn_v2_5_sw_init(struct amdgpu_ip_block *ip_block) > { > + struct amdgpu_device *adev = ip_block->adev; > + int inst = ip_block->instance; > struct amdgpu_ring *ring; > int i, r; > uint32_t reg_count = ARRAY_SIZE(vcn_reg_list_2_5); > uint32_t *ptr; > - struct amdgpu_device *adev = ip_block->adev; > - int inst = ip_block->instance; > > if (adev->vcn.harvest_config & (1 << inst)) > goto sw_init; > @@ -185,7 +185,7 @@ static int vcn_v2_5_sw_init(struct amdgpu_ip_block *ip_block) > if (r) > return r; > sw_init: > - r = amdgpu_vcn_sw_init(adev); > + r = amdgpu_vcn_sw_init(adev, inst); > if (r) > return r; > > diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c > index a7fb5dda51dd..e89088e3cd1d 100644 > --- a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c > +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c > @@ -160,14 +160,15 @@ static int vcn_v3_0_early_init(struct amdgpu_ip_block *ip_block) > */ > static int vcn_v3_0_sw_init(struct amdgpu_ip_block *ip_block) > { > + struct amdgpu_device *adev = ip_block->adev; > + int inst = ip_block->instance; > struct amdgpu_ring *ring; > - int inst = ip_block->instance, j, r; > int vcn_doorbell_index = 0; > uint32_t reg_count = ARRAY_SIZE(vcn_reg_list_3_0); > uint32_t *ptr; > - struct amdgpu_device *adev = ip_block->adev; > + int j, r; > > - r = amdgpu_vcn_sw_init(adev); > + r = amdgpu_vcn_sw_init(adev, inst); > if (r) > return r; > > diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c > index c0c2a071ea15..1b492197c2b7 100644 > --- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c > +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c > @@ -168,14 +168,15 @@ static int vcn_v4_0_fw_shared_init(struct amdgpu_device *adev, int inst_idx) > */ > static int vcn_v4_0_sw_init(struct amdgpu_ip_block *ip_block) > { > - struct amdgpu_ring *ring; > struct amdgpu_device *adev = ip_block->adev; > - int inst = ip_block->instance, r; > + int inst = ip_block->instance; > + struct amdgpu_ring *ring; > + int r; > > uint32_t reg_count = ARRAY_SIZE(vcn_reg_list_4_0); > uint32_t *ptr; > > - r = amdgpu_vcn_sw_init(adev); > + r = amdgpu_vcn_sw_init(adev, inst); > if (r) > return r; > > 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 1d1ee6da7647..5b61000f3004 100644 > --- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c > +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c > @@ -127,12 +127,13 @@ static int vcn_v4_0_3_early_init(struct amdgpu_ip_block *ip_block) > static int vcn_v4_0_3_sw_init(struct amdgpu_ip_block *ip_block) > { > struct amdgpu_device *adev = ip_block->adev; > + int inst = ip_block->instance; > struct amdgpu_ring *ring; > - int inst = ip_block->instance, r, vcn_inst; > + int r, vcn_inst; > uint32_t reg_count = ARRAY_SIZE(vcn_reg_list_4_0_3); > uint32_t *ptr; > > - r = amdgpu_vcn_sw_init(adev); > + r = amdgpu_vcn_sw_init(adev, inst); > if (r) > return r; > > diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c > index 81efc53e7cd3..4d944636d02b 100644 > --- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c > +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c > @@ -131,13 +131,14 @@ static int vcn_v4_0_5_early_init(struct amdgpu_ip_block *ip_block) > */ > static int vcn_v4_0_5_sw_init(struct amdgpu_ip_block *ip_block) > { > - struct amdgpu_ring *ring; > struct amdgpu_device *adev = ip_block->adev; > - int inst = ip_block->instance, r; > + int inst = ip_block->instance; > + struct amdgpu_ring *ring; > uint32_t reg_count = ARRAY_SIZE(vcn_reg_list_4_0_5); > uint32_t *ptr; > + int r; > > - r = amdgpu_vcn_sw_init(adev); > + r = amdgpu_vcn_sw_init(adev, inst); > if (r) > return r; > > diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c > index 7873ca91da4c..8efedf943581 100644 > --- a/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c > +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c > @@ -115,13 +115,14 @@ static int vcn_v5_0_0_early_init(struct amdgpu_ip_block *ip_block) > */ > static int vcn_v5_0_0_sw_init(struct amdgpu_ip_block *ip_block) > { > - struct amdgpu_ring *ring; > struct amdgpu_device *adev = ip_block->adev; > - int inst = ip_block->instance, r; > + int inst = ip_block->instance; > + struct amdgpu_ring *ring; > uint32_t reg_count = ARRAY_SIZE(vcn_reg_list_5_0); > uint32_t *ptr; > + int r; > > - r = amdgpu_vcn_sw_init(adev); > + r = amdgpu_vcn_sw_init(adev, inst); > if (r) > return r; > > -- > 2.34.1 >