Linux 6.13-rc1
[linux-2.6-microblaze.git] / drivers / gpu / drm / amd / amdgpu / vcn_v1_0.c
index 25ba271..10e99c9 100644 (file)
 #define mmUVD_REG_XX_MASK_1_0                  0x05ac
 #define mmUVD_REG_XX_MASK_1_0_BASE_IDX         1
 
+static const struct amdgpu_hwip_reg_entry vcn_reg_list_1_0[] = {
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_POWER_STATUS),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_STATUS),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_CONTEXT_ID),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_CONTEXT_ID2),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_GPCOM_VCPU_DATA0),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_GPCOM_VCPU_DATA1),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_GPCOM_VCPU_CMD),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_BASE_HI),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_BASE_LO),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_BASE_HI2),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_BASE_LO2),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_BASE_HI3),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_BASE_LO3),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_BASE_HI4),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_BASE_LO4),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_RPTR),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_WPTR),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_RPTR2),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_WPTR2),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_RPTR3),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_WPTR3),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_RPTR4),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_WPTR4),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_SIZE),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_SIZE2),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_SIZE3),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_RB_SIZE4),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_PGFSM_CONFIG),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_PGFSM_STATUS),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_DPG_LMA_CTL),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_DPG_LMA_DATA),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_DPG_LMA_MASK),
+       SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_DPG_PAUSE)
+};
+
 static int vcn_v1_0_stop(struct amdgpu_device *adev);
 static void vcn_v1_0_set_dec_ring_funcs(struct amdgpu_device *adev);
 static void vcn_v1_0_set_enc_ring_funcs(struct amdgpu_device *adev);
@@ -59,14 +95,14 @@ static void vcn_v1_0_ring_begin_use(struct amdgpu_ring *ring);
 /**
  * vcn_v1_0_early_init - set function pointers and load microcode
  *
- * @handle: amdgpu_device pointer
+ * @ip_block: Pointer to the amdgpu_ip_block for this hw instance.
  *
  * Set ring and irq function pointers
  * Load microcode from filesystem
  */
-static int vcn_v1_0_early_init(void *handle)
+static int vcn_v1_0_early_init(struct amdgpu_ip_block *ip_block)
 {
-       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       struct amdgpu_device *adev = ip_block->adev;
 
        adev->vcn.num_enc_rings = 2;
 
@@ -74,7 +110,7 @@ static int vcn_v1_0_early_init(void *handle)
        vcn_v1_0_set_enc_ring_funcs(adev);
        vcn_v1_0_set_irq_funcs(adev);
 
-       jpeg_v1_0_early_init(handle);
+       jpeg_v1_0_early_init(ip_block);
 
        return amdgpu_vcn_early_init(adev);
 }
@@ -82,15 +118,17 @@ static int vcn_v1_0_early_init(void *handle)
 /**
  * vcn_v1_0_sw_init - sw init for VCN block
  *
- * @handle: amdgpu_device pointer
+ * @ip_block: Pointer to the amdgpu_ip_block for this hw instance.
  *
  * Load firmware and sw initialization
  */
-static int vcn_v1_0_sw_init(void *handle)
+static int vcn_v1_0_sw_init(struct amdgpu_ip_block *ip_block)
 {
        struct amdgpu_ring *ring;
        int i, r;
-       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       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,
@@ -159,67 +197,70 @@ static int vcn_v1_0_sw_init(void *handle)
                amdgpu_vcn_fwlog_init(adev->vcn.inst);
        }
 
-       r = jpeg_v1_0_sw_init(handle);
+       r = jpeg_v1_0_sw_init(ip_block);
 
+       /* Allocate memory for VCN IP Dump buffer */
+       ptr = kcalloc(adev->vcn.num_vcn_inst * reg_count, sizeof(uint32_t), GFP_KERNEL);
+       if (!ptr) {
+               DRM_ERROR("Failed to allocate memory for VCN IP Dump\n");
+               adev->vcn.ip_dump = NULL;
+       } else {
+               adev->vcn.ip_dump = ptr;
+       }
        return r;
 }
 
 /**
  * vcn_v1_0_sw_fini - sw fini for VCN block
  *
- * @handle: amdgpu_device pointer
+ * @ip_block: Pointer to the amdgpu_ip_block for this hw instance.
  *
  * VCN suspend and free up sw allocation
  */
-static int vcn_v1_0_sw_fini(void *handle)
+static int vcn_v1_0_sw_fini(struct amdgpu_ip_block *ip_block)
 {
        int r;
-       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       struct amdgpu_device *adev = ip_block->adev;
 
        r = amdgpu_vcn_suspend(adev);
        if (r)
                return r;
 
-       jpeg_v1_0_sw_fini(handle);
+       jpeg_v1_0_sw_fini(ip_block);
 
        r = amdgpu_vcn_sw_fini(adev);
 
+       kfree(adev->vcn.ip_dump);
+
        return r;
 }
 
 /**
  * vcn_v1_0_hw_init - start and test VCN block
  *
- * @handle: amdgpu_device pointer
+ * @ip_block: Pointer to the amdgpu_ip_block for this hw instance.
  *
  * Initialize the hardware, boot up the VCPU and do some testing
  */
-static int vcn_v1_0_hw_init(void *handle)
+static int vcn_v1_0_hw_init(struct amdgpu_ip_block *ip_block)
 {
-       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       struct amdgpu_device *adev = ip_block->adev;
        struct amdgpu_ring *ring = &adev->vcn.inst->ring_dec;
        int i, r;
 
        r = amdgpu_ring_test_helper(ring);
        if (r)
-               goto done;
+               return r;
 
        for (i = 0; i < adev->vcn.num_enc_rings; ++i) {
                ring = &adev->vcn.inst->ring_enc[i];
                r = amdgpu_ring_test_helper(ring);
                if (r)
-                       goto done;
+                       return r;
        }
 
        ring = adev->jpeg.inst->ring_dec;
        r = amdgpu_ring_test_helper(ring);
-       if (r)
-               goto done;
-
-done:
-       if (!r)
-               DRM_INFO("VCN decode and encode initialized successfully(under %s).\n",
-                       (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG)?"DPG Mode":"SPG Mode");
 
        return r;
 }
@@ -227,13 +268,13 @@ done:
 /**
  * vcn_v1_0_hw_fini - stop the hardware block
  *
- * @handle: amdgpu_device pointer
+ * @ip_block: Pointer to the amdgpu_ip_block for this hw instance.
  *
  * Stop the VCN block, mark ring as not ready any more
  */
-static int vcn_v1_0_hw_fini(void *handle)
+static int vcn_v1_0_hw_fini(struct amdgpu_ip_block *ip_block)
 {
-       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       struct amdgpu_device *adev = ip_block->adev;
 
        cancel_delayed_work_sync(&adev->vcn.idle_work);
 
@@ -249,14 +290,14 @@ static int vcn_v1_0_hw_fini(void *handle)
 /**
  * vcn_v1_0_suspend - suspend VCN block
  *
- * @handle: amdgpu_device pointer
+ * @ip_block: Pointer to the amdgpu_ip_block for this hw instance.
  *
  * HW fini and suspend VCN block
  */
-static int vcn_v1_0_suspend(void *handle)
+static int vcn_v1_0_suspend(struct amdgpu_ip_block *ip_block)
 {
        int r;
-       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       struct amdgpu_device *adev = ip_block->adev;
        bool idle_work_unexecuted;
 
        idle_work_unexecuted = cancel_delayed_work_sync(&adev->vcn.idle_work);
@@ -265,7 +306,7 @@ static int vcn_v1_0_suspend(void *handle)
                        amdgpu_dpm_enable_uvd(adev, false);
        }
 
-       r = vcn_v1_0_hw_fini(adev);
+       r = vcn_v1_0_hw_fini(ip_block);
        if (r)
                return r;
 
@@ -277,20 +318,19 @@ static int vcn_v1_0_suspend(void *handle)
 /**
  * vcn_v1_0_resume - resume VCN block
  *
- * @handle: amdgpu_device pointer
+ * @ip_block: Pointer to the amdgpu_ip_block for this hw instance.
  *
  * Resume firmware and hw init VCN block
  */
-static int vcn_v1_0_resume(void *handle)
+static int vcn_v1_0_resume(struct amdgpu_ip_block *ip_block)
 {
        int r;
-       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
-       r = amdgpu_vcn_resume(adev);
+       r = amdgpu_vcn_resume(ip_block->adev);
        if (r)
                return r;
 
-       r = vcn_v1_0_hw_init(adev);
+       r = vcn_v1_0_hw_init(ip_block);
 
        return r;
 }
@@ -304,7 +344,7 @@ static int vcn_v1_0_resume(void *handle)
  */
 static void vcn_v1_0_mc_resume_spg_mode(struct amdgpu_device *adev)
 {
-       uint32_t size = AMDGPU_GPU_PAGE_ALIGN(adev->vcn.fw->size + 4);
+       uint32_t size = AMDGPU_GPU_PAGE_ALIGN(adev->vcn.fw[0]->size + 4);
        uint32_t offset;
 
        /* cache window 0: fw */
@@ -371,7 +411,7 @@ static void vcn_v1_0_mc_resume_spg_mode(struct amdgpu_device *adev)
 
 static void vcn_v1_0_mc_resume_dpg_mode(struct amdgpu_device *adev)
 {
-       uint32_t size = AMDGPU_GPU_PAGE_ALIGN(adev->vcn.fw->size + 4);
+       uint32_t size = AMDGPU_GPU_PAGE_ALIGN(adev->vcn.fw[0]->size + 4);
        uint32_t offset;
 
        /* cache window 0: fw */
@@ -1343,9 +1383,9 @@ static bool vcn_v1_0_is_idle(void *handle)
        return (RREG32_SOC15(VCN, 0, mmUVD_STATUS) == UVD_STATUS__IDLE);
 }
 
-static int vcn_v1_0_wait_for_idle(void *handle)
+static int vcn_v1_0_wait_for_idle(struct amdgpu_ip_block *ip_block)
 {
-       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       struct amdgpu_device *adev = ip_block->adev;
        int ret;
 
        ret = SOC15_WAIT_ON_RREG(VCN, 0, mmUVD_STATUS, UVD_STATUS__IDLE,
@@ -1884,10 +1924,69 @@ void vcn_v1_0_ring_end_use(struct amdgpu_ring *ring)
        mutex_unlock(&ring->adev->vcn.vcn1_jpeg1_workaround);
 }
 
+static void vcn_v1_0_print_ip_state(struct amdgpu_ip_block *ip_block, struct drm_printer *p)
+{
+       struct amdgpu_device *adev = ip_block->adev;
+       int i, j;
+       uint32_t reg_count = ARRAY_SIZE(vcn_reg_list_1_0);
+       uint32_t inst_off, is_powered;
+
+       if (!adev->vcn.ip_dump)
+               return;
+
+       drm_printf(p, "num_instances:%d\n", adev->vcn.num_vcn_inst);
+       for (i = 0; i < adev->vcn.num_vcn_inst; i++) {
+               if (adev->vcn.harvest_config & (1 << i)) {
+                       drm_printf(p, "\nHarvested Instance:VCN%d Skipping dump\n", i);
+                       continue;
+               }
+
+               inst_off = i * reg_count;
+               is_powered = (adev->vcn.ip_dump[inst_off] &
+                               UVD_POWER_STATUS__UVD_POWER_STATUS_MASK) != 1;
+
+               if (is_powered) {
+                       drm_printf(p, "\nActive Instance:VCN%d\n", i);
+                       for (j = 0; j < reg_count; j++)
+                               drm_printf(p, "%-50s \t 0x%08x\n", vcn_reg_list_1_0[j].reg_name,
+                                          adev->vcn.ip_dump[inst_off + j]);
+               } else {
+                       drm_printf(p, "\nInactive Instance:VCN%d\n", i);
+               }
+       }
+}
+
+static void vcn_v1_0_dump_ip_state(struct amdgpu_ip_block *ip_block)
+{
+       struct amdgpu_device *adev = ip_block->adev;
+       int i, j;
+       bool is_powered;
+       uint32_t inst_off;
+       uint32_t reg_count = ARRAY_SIZE(vcn_reg_list_1_0);
+
+       if (!adev->vcn.ip_dump)
+               return;
+
+       for (i = 0; i < adev->vcn.num_vcn_inst; i++) {
+               if (adev->vcn.harvest_config & (1 << i))
+                       continue;
+
+               inst_off = i * reg_count;
+               /* mmUVD_POWER_STATUS is always readable and is first element of the array */
+               adev->vcn.ip_dump[inst_off] = RREG32_SOC15(VCN, i, mmUVD_POWER_STATUS);
+               is_powered = (adev->vcn.ip_dump[inst_off] &
+                               UVD_POWER_STATUS__UVD_POWER_STATUS_MASK) != 1;
+
+               if (is_powered)
+                       for (j = 1; j < reg_count; j++)
+                               adev->vcn.ip_dump[inst_off + j] =
+                                       RREG32(SOC15_REG_ENTRY_OFFSET_INST(vcn_reg_list_1_0[j], i));
+       }
+}
+
 static const struct amd_ip_funcs vcn_v1_0_ip_funcs = {
        .name = "vcn_v1_0",
        .early_init = vcn_v1_0_early_init,
-       .late_init = NULL,
        .sw_init = vcn_v1_0_sw_init,
        .sw_fini = vcn_v1_0_sw_fini,
        .hw_init = vcn_v1_0_hw_init,
@@ -1896,12 +1995,10 @@ static const struct amd_ip_funcs vcn_v1_0_ip_funcs = {
        .resume = vcn_v1_0_resume,
        .is_idle = vcn_v1_0_is_idle,
        .wait_for_idle = vcn_v1_0_wait_for_idle,
-       .check_soft_reset = NULL /* vcn_v1_0_check_soft_reset */,
-       .pre_soft_reset = NULL /* vcn_v1_0_pre_soft_reset */,
-       .soft_reset = NULL /* vcn_v1_0_soft_reset */,
-       .post_soft_reset = NULL /* vcn_v1_0_post_soft_reset */,
        .set_clockgating_state = vcn_v1_0_set_clockgating_state,
        .set_powergating_state = vcn_v1_0_set_powergating_state,
+       .dump_ip_state = vcn_v1_0_dump_ip_state,
+       .print_ip_state = vcn_v1_0_print_ip_state,
 };
 
 /*
@@ -2041,7 +2138,6 @@ static const struct amdgpu_ring_funcs vcn_v1_0_enc_ring_vm_funcs = {
 static void vcn_v1_0_set_dec_ring_funcs(struct amdgpu_device *adev)
 {
        adev->vcn.inst->ring_dec.funcs = &vcn_v1_0_dec_ring_vm_funcs;
-       DRM_INFO("VCN decode is enabled in VM mode\n");
 }
 
 static void vcn_v1_0_set_enc_ring_funcs(struct amdgpu_device *adev)
@@ -2050,8 +2146,6 @@ static void vcn_v1_0_set_enc_ring_funcs(struct amdgpu_device *adev)
 
        for (i = 0; i < adev->vcn.num_enc_rings; ++i)
                adev->vcn.inst->ring_enc[i].funcs = &vcn_v1_0_enc_ring_vm_funcs;
-
-       DRM_INFO("VCN encode is enabled in VM mode\n");
 }
 
 static const struct amdgpu_irq_src_funcs vcn_v1_0_irq_funcs = {