Linux 6.13-rc1
[linux-2.6-microblaze.git] / drivers / gpu / drm / amd / amdgpu / soc15.c
index 1c61445..ede0727 100644 (file)
@@ -90,8 +90,8 @@ static const struct amd_ip_funcs soc15_common_ip_funcs;
 /* Vega, Raven, Arcturus */
 static const struct amdgpu_video_codec_info vega_video_codecs_encode_array[] =
 {
-       {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 2304, 0)},
-       {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 4096, 2304, 0)},
+       {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 0)},
+       {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 4096, 4096, 0)},
 };
 
 static const struct amdgpu_video_codecs vega_video_codecs_encode =
@@ -143,7 +143,7 @@ static const struct amdgpu_video_codec_info rn_video_codecs_decode_array[] =
        {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
        {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4096, 4)},
        {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
-       {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
+       {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 16384, 16384, 0)},
        {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
 };
 
@@ -156,7 +156,7 @@ static const struct amdgpu_video_codecs rn_video_codecs_decode =
 static const struct amdgpu_video_codec_info vcn_4_0_3_video_codecs_decode_array[] = {
        {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
        {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
-       {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
+       {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 16384, 16384, 0)},
        {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
        {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_AV1, 8192, 4352, 0)},
 };
@@ -326,7 +326,8 @@ static u32 soc15_get_xclk(struct amdgpu_device *adev)
 
        if (amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(12, 0, 0) ||
            amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(12, 0, 1) ||
-           amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(13, 0, 6))
+           amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(13, 0, 6) ||
+           amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(13, 0, 14))
                return 10000;
        if (amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(10, 0, 0) ||
            amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(10, 0, 1))
@@ -502,7 +503,7 @@ static int soc15_asic_baco_reset(struct amdgpu_device *adev)
 static enum amd_reset_method
 soc15_asic_reset_method(struct amdgpu_device *adev)
 {
-       bool baco_reset = false;
+       int baco_reset = 0;
        bool connected_to_cpu = false;
        struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
 
@@ -540,7 +541,7 @@ soc15_asic_reset_method(struct amdgpu_device *adev)
                         */
                        if (ras && adev->ras_enabled &&
                            adev->pm.fw_version <= 0x283400)
-                               baco_reset = false;
+                               baco_reset = 0;
                } else {
                        baco_reset = amdgpu_dpm_is_baco_supported(adev);
                }
@@ -554,6 +555,7 @@ soc15_asic_reset_method(struct amdgpu_device *adev)
                        return AMD_RESET_METHOD_MODE2;
                break;
        case IP_VERSION(13, 0, 6):
+       case IP_VERSION(13, 0, 14):
                /* Use gpu_recovery param to target a reset method.
                 * Enable triggering of GPU reset only if specified
                 * by module parameter.
@@ -576,20 +578,16 @@ soc15_asic_reset_method(struct amdgpu_device *adev)
 
 static bool soc15_need_reset_on_resume(struct amdgpu_device *adev)
 {
-       u32 sol_reg;
-
-       sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81);
-
        /* Will reset for the following suspend abort cases.
-        * 1) Only reset limit on APU side, dGPU hasn't checked yet.
-        * 2) S3 suspend abort and TOS already launched.
+        * 1) Only reset on APU side, dGPU hasn't checked yet.
+        * 2) S3 suspend aborted in the normal S3 suspend or
+        *    performing pm core test.
         */
        if (adev->flags & AMD_IS_APU && adev->in_s3 &&
-                       !adev->suspend_complete &&
-                       sol_reg)
+                       !pm_resume_via_firmware())
                return true;
-
-       return false;
+       else
+               return false;
 }
 
 static int soc15_asic_reset(struct amdgpu_device *adev)
@@ -599,11 +597,17 @@ static int soc15_asic_reset(struct amdgpu_device *adev)
         * successfully. So now, temporarily enable it for the
         * S3 suspend abort case.
         */
-       if (((adev->apu_flags & AMD_APU_IS_RAVEN) ||
-           (adev->apu_flags & AMD_APU_IS_RAVEN2)) &&
-               !soc15_need_reset_on_resume(adev))
+
+       if ((adev->apu_flags & AMD_APU_IS_PICASSO ||
+                       !(adev->apu_flags & AMD_APU_IS_RAVEN)) &&
+                       soc15_need_reset_on_resume(adev))
+               goto asic_reset;
+
+       if ((adev->apu_flags & AMD_APU_IS_RAVEN) ||
+                       (adev->apu_flags & AMD_APU_IS_RAVEN2))
                return 0;
 
+asic_reset:
        switch (soc15_asic_reset_method(adev)) {
        case AMD_RESET_METHOD_PCI:
                dev_info(adev->dev, "PCI reset\n");
@@ -620,7 +624,7 @@ static int soc15_asic_reset(struct amdgpu_device *adev)
        }
 }
 
-static bool soc15_supports_baco(struct amdgpu_device *adev)
+static int soc15_supports_baco(struct amdgpu_device *adev)
 {
        switch (amdgpu_ip_version(adev, MP1_HWIP, 0)) {
        case IP_VERSION(9, 0, 0):
@@ -628,13 +632,13 @@ static bool soc15_supports_baco(struct amdgpu_device *adev)
                if (adev->asic_type == CHIP_VEGA20) {
                        if (adev->psp.sos.fw_version >= 0x80067)
                                return amdgpu_dpm_is_baco_supported(adev);
-                       return false;
+                       return 0;
                } else {
                        return amdgpu_dpm_is_baco_supported(adev);
                }
                break;
        default:
-               return false;
+               return 0;
        }
 }
 
@@ -827,6 +831,10 @@ static bool soc15_need_reset_on_init(struct amdgpu_device *adev)
        if (adev->asic_type == CHIP_RENOIR)
                return true;
 
+       if (amdgpu_gmc_need_reset_on_init(adev))
+               return true;
+       if (amdgpu_psp_tos_reload_needed(adev))
+               return true;
        /* Just return false for soc15 GPUs.  Reset does not seem to
         * be necessary.
         */
@@ -918,7 +926,6 @@ static const struct amdgpu_asic_funcs aqua_vanjaram_asic_funcs =
        .get_config_memsize = &soc15_get_config_memsize,
        .need_full_reset = &soc15_need_full_reset,
        .init_doorbell_index = &aqua_vanjaram_doorbell_index_init,
-       .get_pcie_usage = &amdgpu_nbio_get_pcie_usage,
        .need_reset_on_init = &soc15_need_reset_on_init,
        .get_pcie_replay_count = &amdgpu_nbio_get_pcie_replay_count,
        .supports_baco = &soc15_supports_baco,
@@ -928,15 +935,11 @@ static const struct amdgpu_asic_funcs aqua_vanjaram_asic_funcs =
        .get_reg_state = &aqua_vanjaram_get_reg_state,
 };
 
-static int soc15_common_early_init(void *handle)
+static int soc15_common_early_init(struct amdgpu_ip_block *ip_block)
 {
-#define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
-       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       struct amdgpu_device *adev = ip_block->adev;
 
-       if (!amdgpu_sriov_vf(adev)) {
-               adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET;
-               adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET;
-       }
+       adev->nbio.funcs->set_reg_remap(adev);
        adev->smc_rreg = NULL;
        adev->smc_wreg = NULL;
        adev->pcie_rreg = &amdgpu_device_indirect_rreg;
@@ -1173,6 +1176,7 @@ static int soc15_common_early_init(void *handle)
                adev->external_rev_id = adev->rev_id + 0x3c;
                break;
        case IP_VERSION(9, 4, 3):
+       case IP_VERSION(9, 4, 4):
                adev->asic_funcs = &aqua_vanjaram_asic_funcs;
                adev->cg_flags =
                        AMD_CG_SUPPORT_GFX_MGCG | AMD_CG_SUPPORT_GFX_CGCG |
@@ -1184,12 +1188,8 @@ static int soc15_common_early_init(void *handle)
                        AMD_PG_SUPPORT_VCN |
                        AMD_PG_SUPPORT_VCN_DPG |
                        AMD_PG_SUPPORT_JPEG;
+               /*TODO: need a new external_rev_id for GC 9.4.4? */
                adev->external_rev_id = adev->rev_id + 0x46;
-               /* GC 9.4.3 uses MMIO register region hole at a different offset */
-               if (!amdgpu_sriov_vf(adev)) {
-                       adev->rmmio_remap.reg_offset = 0x1A000;
-                       adev->rmmio_remap.bus_addr = adev->rmmio_base + 0x1A000;
-               }
                break;
        default:
                /* FIXME: not supported yet */
@@ -1204,9 +1204,9 @@ static int soc15_common_early_init(void *handle)
        return 0;
 }
 
-static int soc15_common_late_init(void *handle)
+static int soc15_common_late_init(struct amdgpu_ip_block *ip_block)
 {
-       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       struct amdgpu_device *adev = ip_block->adev;
 
        if (amdgpu_sriov_vf(adev))
                xgpu_ai_mailbox_get_irq(adev);
@@ -1219,9 +1219,9 @@ static int soc15_common_late_init(void *handle)
        return 0;
 }
 
-static int soc15_common_sw_init(void *handle)
+static int soc15_common_sw_init(struct amdgpu_ip_block *ip_block)
 {
-       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       struct amdgpu_device *adev = ip_block->adev;
 
        if (amdgpu_sriov_vf(adev))
                xgpu_ai_mailbox_add_irq_id(adev);
@@ -1233,9 +1233,9 @@ static int soc15_common_sw_init(void *handle)
        return 0;
 }
 
-static int soc15_common_sw_fini(void *handle)
+static int soc15_common_sw_fini(struct amdgpu_ip_block *ip_block)
 {
-       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       struct amdgpu_device *adev = ip_block->adev;
 
        if (adev->df.funcs &&
            adev->df.funcs->sw_fini)
@@ -1257,9 +1257,9 @@ static void soc15_sdma_doorbell_range_init(struct amdgpu_device *adev)
        }
 }
 
-static int soc15_common_hw_init(void *handle)
+static int soc15_common_hw_init(struct amdgpu_ip_block *ip_block)
 {
-       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       struct amdgpu_device *adev = ip_block->adev;
 
        /* enable aspm */
        soc15_program_aspm(adev);
@@ -1286,9 +1286,9 @@ static int soc15_common_hw_init(void *handle)
        return 0;
 }
 
-static int soc15_common_hw_fini(void *handle)
+static int soc15_common_hw_fini(struct amdgpu_ip_block *ip_block)
 {
-       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       struct amdgpu_device *adev = ip_block->adev;
 
        /* Disable the doorbell aperture and selfring doorbell aperture
         * separately in hw_fini because soc15_enable_doorbell_aperture
@@ -1301,7 +1301,13 @@ static int soc15_common_hw_fini(void *handle)
        if (amdgpu_sriov_vf(adev))
                xgpu_ai_mailbox_put_irq(adev);
 
-       if (adev->nbio.ras_if &&
+       /*
+        * For minimal init, late_init is not called, hence RAS irqs are not
+        * enabled.
+        */
+       if ((!amdgpu_sriov_vf(adev)) &&
+           (adev->init_lvl->level != AMDGPU_INIT_LEVEL_MINIMAL_XGMI) &&
+           adev->nbio.ras_if &&
            amdgpu_ras_is_supported(adev, adev->nbio.ras_if->block)) {
                if (adev->nbio.ras &&
                    adev->nbio.ras->init_ras_controller_interrupt)
@@ -1314,22 +1320,20 @@ static int soc15_common_hw_fini(void *handle)
        return 0;
 }
 
-static int soc15_common_suspend(void *handle)
+static int soc15_common_suspend(struct amdgpu_ip_block *ip_block)
 {
-       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-
-       return soc15_common_hw_fini(adev);
+       return soc15_common_hw_fini(ip_block);
 }
 
-static int soc15_common_resume(void *handle)
+static int soc15_common_resume(struct amdgpu_ip_block *ip_block)
 {
-       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       struct amdgpu_device *adev = ip_block->adev;
 
        if (soc15_need_reset_on_resume(adev)) {
                dev_info(adev->dev, "S3 suspend abort case, let's reset ASIC.\n");
                soc15_asic_reset(adev);
        }
-       return soc15_common_hw_init(adev);
+       return soc15_common_hw_init(ip_block);
 }
 
 static bool soc15_common_is_idle(void *handle)
@@ -1337,16 +1341,6 @@ static bool soc15_common_is_idle(void *handle)
        return true;
 }
 
-static int soc15_common_wait_for_idle(void *handle)
-{
-       return 0;
-}
-
-static int soc15_common_soft_reset(void *handle)
-{
-       return 0;
-}
-
 static void soc15_update_drm_clock_gating(struct amdgpu_device *adev, bool enable)
 {
        uint32_t def, data;
@@ -1458,7 +1452,8 @@ static void soc15_common_get_clockgating_state(void *handle, u64 *flags)
                adev->hdp.funcs->get_clock_gating_state(adev, flags);
 
        if ((amdgpu_ip_version(adev, MP0_HWIP, 0) != IP_VERSION(13, 0, 2)) &&
-           (amdgpu_ip_version(adev, MP0_HWIP, 0) != IP_VERSION(13, 0, 6))) {
+           (amdgpu_ip_version(adev, MP0_HWIP, 0) != IP_VERSION(13, 0, 6)) &&
+           (amdgpu_ip_version(adev, MP0_HWIP, 0) != IP_VERSION(13, 0, 14))) {
                /* AMD_CG_SUPPORT_DRM_MGCG */
                data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
                if (!(data & 0x01000000))
@@ -1496,8 +1491,6 @@ static const struct amd_ip_funcs soc15_common_ip_funcs = {
        .suspend = soc15_common_suspend,
        .resume = soc15_common_resume,
        .is_idle = soc15_common_is_idle,
-       .wait_for_idle = soc15_common_wait_for_idle,
-       .soft_reset = soc15_common_soft_reset,
        .set_clockgating_state = soc15_common_set_clockgating_state,
        .set_powergating_state = soc15_common_set_powergating_state,
        .get_clockgating_state= soc15_common_get_clockgating_state,