10ba96fd3SBen Li /*
20ba96fd3SBen Li * Copyright 2023 Advanced Micro Devices, Inc.
30ba96fd3SBen Li *
40ba96fd3SBen Li * Permission is hereby granted, free of charge, to any person obtaining a
50ba96fd3SBen Li * copy of this software and associated documentation files (the "Software"),
60ba96fd3SBen Li * to deal in the Software without restriction, including without limitation
70ba96fd3SBen Li * the rights to use, copy, modify, merge, publish, distribute, sublicense,
80ba96fd3SBen Li * and/or sell copies of the Software, and to permit persons to whom the
90ba96fd3SBen Li * Software is furnished to do so, subject to the following conditions:
100ba96fd3SBen Li *
110ba96fd3SBen Li * The above copyright notice and this permission notice shall be included in
120ba96fd3SBen Li * all copies or substantial portions of the Software.
130ba96fd3SBen Li *
140ba96fd3SBen Li * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
150ba96fd3SBen Li * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
160ba96fd3SBen Li * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
170ba96fd3SBen Li * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
180ba96fd3SBen Li * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
190ba96fd3SBen Li * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
200ba96fd3SBen Li * OTHER DEALINGS IN THE SOFTWARE.
210ba96fd3SBen Li *
220ba96fd3SBen Li */
230ba96fd3SBen Li
240ba96fd3SBen Li #include <linux/pci.h>
250ba96fd3SBen Li
260ba96fd3SBen Li #include "amdgpu.h"
270ba96fd3SBen Li #include "amdgpu_ih.h"
280ba96fd3SBen Li
290ba96fd3SBen Li #include "oss/osssys_6_1_0_offset.h"
300ba96fd3SBen Li #include "oss/osssys_6_1_0_sh_mask.h"
310ba96fd3SBen Li
320ba96fd3SBen Li #include "soc15_common.h"
330ba96fd3SBen Li #include "ih_v6_1.h"
340ba96fd3SBen Li
350ba96fd3SBen Li #define MAX_REARM_RETRY 10
360ba96fd3SBen Li
370ba96fd3SBen Li static void ih_v6_1_set_interrupt_funcs(struct amdgpu_device *adev);
380ba96fd3SBen Li
390ba96fd3SBen Li /**
400ba96fd3SBen Li * ih_v6_1_init_register_offset - Initialize register offset for ih rings
410ba96fd3SBen Li *
420ba96fd3SBen Li * @adev: amdgpu_device pointer
430ba96fd3SBen Li *
440ba96fd3SBen Li * Initialize register offset ih rings (IH_V6_0).
450ba96fd3SBen Li */
ih_v6_1_init_register_offset(struct amdgpu_device * adev)460ba96fd3SBen Li static void ih_v6_1_init_register_offset(struct amdgpu_device *adev)
470ba96fd3SBen Li {
480ba96fd3SBen Li struct amdgpu_ih_regs *ih_regs;
490ba96fd3SBen Li
500ba96fd3SBen Li /* ih ring 2 is removed
510ba96fd3SBen Li * ih ring and ih ring 1 are available */
520ba96fd3SBen Li if (adev->irq.ih.ring_size) {
530ba96fd3SBen Li ih_regs = &adev->irq.ih.ih_regs;
540ba96fd3SBen Li ih_regs->ih_rb_base = SOC15_REG_OFFSET(OSSSYS, 0, regIH_RB_BASE);
550ba96fd3SBen Li ih_regs->ih_rb_base_hi = SOC15_REG_OFFSET(OSSSYS, 0, regIH_RB_BASE_HI);
560ba96fd3SBen Li ih_regs->ih_rb_cntl = SOC15_REG_OFFSET(OSSSYS, 0, regIH_RB_CNTL);
570ba96fd3SBen Li ih_regs->ih_rb_wptr = SOC15_REG_OFFSET(OSSSYS, 0, regIH_RB_WPTR);
580ba96fd3SBen Li ih_regs->ih_rb_rptr = SOC15_REG_OFFSET(OSSSYS, 0, regIH_RB_RPTR);
590ba96fd3SBen Li ih_regs->ih_doorbell_rptr = SOC15_REG_OFFSET(OSSSYS, 0, regIH_DOORBELL_RPTR);
600ba96fd3SBen Li ih_regs->ih_rb_wptr_addr_lo = SOC15_REG_OFFSET(OSSSYS, 0, regIH_RB_WPTR_ADDR_LO);
610ba96fd3SBen Li ih_regs->ih_rb_wptr_addr_hi = SOC15_REG_OFFSET(OSSSYS, 0, regIH_RB_WPTR_ADDR_HI);
620ba96fd3SBen Li ih_regs->psp_reg_id = PSP_REG_IH_RB_CNTL;
630ba96fd3SBen Li }
640ba96fd3SBen Li
650ba96fd3SBen Li if (adev->irq.ih1.ring_size) {
660ba96fd3SBen Li ih_regs = &adev->irq.ih1.ih_regs;
670ba96fd3SBen Li ih_regs->ih_rb_base = SOC15_REG_OFFSET(OSSSYS, 0, regIH_RB_BASE_RING1);
680ba96fd3SBen Li ih_regs->ih_rb_base_hi = SOC15_REG_OFFSET(OSSSYS, 0, regIH_RB_BASE_HI_RING1);
690ba96fd3SBen Li ih_regs->ih_rb_cntl = SOC15_REG_OFFSET(OSSSYS, 0, regIH_RB_CNTL_RING1);
700ba96fd3SBen Li ih_regs->ih_rb_wptr = SOC15_REG_OFFSET(OSSSYS, 0, regIH_RB_WPTR_RING1);
710ba96fd3SBen Li ih_regs->ih_rb_rptr = SOC15_REG_OFFSET(OSSSYS, 0, regIH_RB_RPTR_RING1);
720ba96fd3SBen Li ih_regs->ih_doorbell_rptr = SOC15_REG_OFFSET(OSSSYS, 0, regIH_DOORBELL_RPTR_RING1);
730ba96fd3SBen Li ih_regs->psp_reg_id = PSP_REG_IH_RB_CNTL_RING1;
740ba96fd3SBen Li }
750ba96fd3SBen Li }
760ba96fd3SBen Li
770ba96fd3SBen Li /**
780ba96fd3SBen Li * force_update_wptr_for_self_int - Force update the wptr for self interrupt
790ba96fd3SBen Li *
800ba96fd3SBen Li * @adev: amdgpu_device pointer
810ba96fd3SBen Li * @threshold: threshold to trigger the wptr reporting
820ba96fd3SBen Li * @timeout: timeout to trigger the wptr reporting
830ba96fd3SBen Li * @enabled: Enable/disable timeout flush mechanism
840ba96fd3SBen Li *
850ba96fd3SBen Li * threshold input range: 0 ~ 15, default 0,
860ba96fd3SBen Li * real_threshold = 2^threshold
870ba96fd3SBen Li * timeout input range: 0 ~ 20, default 8,
880ba96fd3SBen Li * real_timeout = (2^timeout) * 1024 / (socclk_freq)
890ba96fd3SBen Li *
900ba96fd3SBen Li * Force update wptr for self interrupt ( >= SIENNA_CICHLID).
910ba96fd3SBen Li */
920ba96fd3SBen Li static void
force_update_wptr_for_self_int(struct amdgpu_device * adev,u32 threshold,u32 timeout,bool enabled)930ba96fd3SBen Li force_update_wptr_for_self_int(struct amdgpu_device *adev,
940ba96fd3SBen Li u32 threshold, u32 timeout, bool enabled)
950ba96fd3SBen Li {
960ba96fd3SBen Li u32 ih_cntl, ih_rb_cntl;
970ba96fd3SBen Li
980ba96fd3SBen Li ih_cntl = RREG32_SOC15(OSSSYS, 0, regIH_CNTL2);
990ba96fd3SBen Li ih_rb_cntl = RREG32_SOC15(OSSSYS, 0, regIH_RB_CNTL_RING1);
1000ba96fd3SBen Li
1010ba96fd3SBen Li ih_cntl = REG_SET_FIELD(ih_cntl, IH_CNTL2,
1020ba96fd3SBen Li SELF_IV_FORCE_WPTR_UPDATE_TIMEOUT, timeout);
1030ba96fd3SBen Li ih_cntl = REG_SET_FIELD(ih_cntl, IH_CNTL2,
1040ba96fd3SBen Li SELF_IV_FORCE_WPTR_UPDATE_ENABLE, enabled);
1050ba96fd3SBen Li ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL_RING1,
1060ba96fd3SBen Li RB_USED_INT_THRESHOLD, threshold);
1070ba96fd3SBen Li
1080ba96fd3SBen Li if (amdgpu_sriov_vf(adev) && amdgpu_sriov_reg_indirect_ih(adev)) {
1090ba96fd3SBen Li if (psp_reg_program(&adev->psp, PSP_REG_IH_RB_CNTL_RING1, ih_rb_cntl))
1100ba96fd3SBen Li return;
1110ba96fd3SBen Li } else {
1120ba96fd3SBen Li WREG32_SOC15(OSSSYS, 0, regIH_RB_CNTL_RING1, ih_rb_cntl);
1130ba96fd3SBen Li }
1140ba96fd3SBen Li
1150ba96fd3SBen Li WREG32_SOC15(OSSSYS, 0, regIH_CNTL2, ih_cntl);
1160ba96fd3SBen Li }
1170ba96fd3SBen Li
1180ba96fd3SBen Li /**
1190ba96fd3SBen Li * ih_v6_1_toggle_ring_interrupts - toggle the interrupt ring buffer
1200ba96fd3SBen Li *
1210ba96fd3SBen Li * @adev: amdgpu_device pointer
1220ba96fd3SBen Li * @ih: amdgpu_ih_ring pointer
1230ba96fd3SBen Li * @enable: true - enable the interrupts, false - disable the interrupts
1240ba96fd3SBen Li *
1250ba96fd3SBen Li * Toggle the interrupt ring buffer (IH_V6_0)
1260ba96fd3SBen Li */
ih_v6_1_toggle_ring_interrupts(struct amdgpu_device * adev,struct amdgpu_ih_ring * ih,bool enable)1270ba96fd3SBen Li static int ih_v6_1_toggle_ring_interrupts(struct amdgpu_device *adev,
1280ba96fd3SBen Li struct amdgpu_ih_ring *ih,
1290ba96fd3SBen Li bool enable)
1300ba96fd3SBen Li {
1310ba96fd3SBen Li struct amdgpu_ih_regs *ih_regs;
1320ba96fd3SBen Li uint32_t tmp;
1330ba96fd3SBen Li
1340ba96fd3SBen Li ih_regs = &ih->ih_regs;
1350ba96fd3SBen Li
1360ba96fd3SBen Li tmp = RREG32(ih_regs->ih_rb_cntl);
1370ba96fd3SBen Li tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, RB_ENABLE, (enable ? 1 : 0));
1380ba96fd3SBen Li /* enable_intr field is only valid in ring0 */
1390ba96fd3SBen Li if (ih == &adev->irq.ih)
1400ba96fd3SBen Li tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, ENABLE_INTR, (enable ? 1 : 0));
1410ba96fd3SBen Li
1420ba96fd3SBen Li if (amdgpu_sriov_vf(adev) && amdgpu_sriov_reg_indirect_ih(adev)) {
1430ba96fd3SBen Li if (psp_reg_program(&adev->psp, ih_regs->psp_reg_id, tmp))
1440ba96fd3SBen Li return -ETIMEDOUT;
1450ba96fd3SBen Li } else {
1460ba96fd3SBen Li WREG32(ih_regs->ih_rb_cntl, tmp);
1470ba96fd3SBen Li }
1480ba96fd3SBen Li
1490ba96fd3SBen Li if (enable) {
1500ba96fd3SBen Li ih->enabled = true;
1510ba96fd3SBen Li } else {
1520ba96fd3SBen Li /* set rptr, wptr to 0 */
1530ba96fd3SBen Li WREG32(ih_regs->ih_rb_rptr, 0);
1540ba96fd3SBen Li WREG32(ih_regs->ih_rb_wptr, 0);
1550ba96fd3SBen Li ih->enabled = false;
1560ba96fd3SBen Li ih->rptr = 0;
1570ba96fd3SBen Li }
1580ba96fd3SBen Li
1590ba96fd3SBen Li return 0;
1600ba96fd3SBen Li }
1610ba96fd3SBen Li
1620ba96fd3SBen Li /**
1630ba96fd3SBen Li * ih_v6_1_toggle_interrupts - Toggle all the available interrupt ring buffers
1640ba96fd3SBen Li *
1650ba96fd3SBen Li * @adev: amdgpu_device pointer
1660ba96fd3SBen Li * @enable: enable or disable interrupt ring buffers
1670ba96fd3SBen Li *
1680ba96fd3SBen Li * Toggle all the available interrupt ring buffers (IH_V6_0).
1690ba96fd3SBen Li */
ih_v6_1_toggle_interrupts(struct amdgpu_device * adev,bool enable)1700ba96fd3SBen Li static int ih_v6_1_toggle_interrupts(struct amdgpu_device *adev, bool enable)
1710ba96fd3SBen Li {
1720ba96fd3SBen Li struct amdgpu_ih_ring *ih[] = {&adev->irq.ih, &adev->irq.ih1};
1730ba96fd3SBen Li int i;
1740ba96fd3SBen Li int r;
1750ba96fd3SBen Li
1760ba96fd3SBen Li for (i = 0; i < ARRAY_SIZE(ih); i++) {
1770ba96fd3SBen Li if (ih[i]->ring_size) {
1780ba96fd3SBen Li r = ih_v6_1_toggle_ring_interrupts(adev, ih[i], enable);
1790ba96fd3SBen Li if (r)
1800ba96fd3SBen Li return r;
1810ba96fd3SBen Li }
1820ba96fd3SBen Li }
1830ba96fd3SBen Li
1840ba96fd3SBen Li return 0;
1850ba96fd3SBen Li }
1860ba96fd3SBen Li
ih_v6_1_rb_cntl(struct amdgpu_ih_ring * ih,uint32_t ih_rb_cntl)1870ba96fd3SBen Li static uint32_t ih_v6_1_rb_cntl(struct amdgpu_ih_ring *ih, uint32_t ih_rb_cntl)
1880ba96fd3SBen Li {
1890ba96fd3SBen Li int rb_bufsz = order_base_2(ih->ring_size / 4);
1900ba96fd3SBen Li
1910ba96fd3SBen Li ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL,
1920ba96fd3SBen Li MC_SPACE, ih->use_bus_addr ? 2 : 4);
1930ba96fd3SBen Li ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL,
1940ba96fd3SBen Li WPTR_OVERFLOW_CLEAR, 1);
1950ba96fd3SBen Li ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL,
1960ba96fd3SBen Li WPTR_OVERFLOW_ENABLE, 1);
1970ba96fd3SBen Li ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, RB_SIZE, rb_bufsz);
1980ba96fd3SBen Li /* Ring Buffer write pointer writeback. If enabled, IH_RB_WPTR register
1990ba96fd3SBen Li * value is written to memory
2000ba96fd3SBen Li */
2010ba96fd3SBen Li ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL,
2020ba96fd3SBen Li WPTR_WRITEBACK_ENABLE, 1);
2030ba96fd3SBen Li ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, MC_SNOOP, 1);
2040ba96fd3SBen Li ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, MC_RO, 0);
2050ba96fd3SBen Li ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, MC_VMID, 0);
2060ba96fd3SBen Li
2070ba96fd3SBen Li return ih_rb_cntl;
2080ba96fd3SBen Li }
2090ba96fd3SBen Li
ih_v6_1_doorbell_rptr(struct amdgpu_ih_ring * ih)2100ba96fd3SBen Li static uint32_t ih_v6_1_doorbell_rptr(struct amdgpu_ih_ring *ih)
2110ba96fd3SBen Li {
2120ba96fd3SBen Li u32 ih_doorbell_rtpr = 0;
2130ba96fd3SBen Li
2140ba96fd3SBen Li if (ih->use_doorbell) {
2150ba96fd3SBen Li ih_doorbell_rtpr = REG_SET_FIELD(ih_doorbell_rtpr,
2160ba96fd3SBen Li IH_DOORBELL_RPTR, OFFSET,
2170ba96fd3SBen Li ih->doorbell_index);
2180ba96fd3SBen Li ih_doorbell_rtpr = REG_SET_FIELD(ih_doorbell_rtpr,
2190ba96fd3SBen Li IH_DOORBELL_RPTR,
2200ba96fd3SBen Li ENABLE, 1);
2210ba96fd3SBen Li } else {
2220ba96fd3SBen Li ih_doorbell_rtpr = REG_SET_FIELD(ih_doorbell_rtpr,
2230ba96fd3SBen Li IH_DOORBELL_RPTR,
2240ba96fd3SBen Li ENABLE, 0);
2250ba96fd3SBen Li }
2260ba96fd3SBen Li return ih_doorbell_rtpr;
2270ba96fd3SBen Li }
2280ba96fd3SBen Li
2290ba96fd3SBen Li /**
2300ba96fd3SBen Li * ih_v6_1_enable_ring - enable an ih ring buffer
2310ba96fd3SBen Li *
2320ba96fd3SBen Li * @adev: amdgpu_device pointer
2330ba96fd3SBen Li * @ih: amdgpu_ih_ring pointer
2340ba96fd3SBen Li *
2350ba96fd3SBen Li * Enable an ih ring buffer (IH_V6_0)
2360ba96fd3SBen Li */
ih_v6_1_enable_ring(struct amdgpu_device * adev,struct amdgpu_ih_ring * ih)2370ba96fd3SBen Li static int ih_v6_1_enable_ring(struct amdgpu_device *adev,
2380ba96fd3SBen Li struct amdgpu_ih_ring *ih)
2390ba96fd3SBen Li {
2400ba96fd3SBen Li struct amdgpu_ih_regs *ih_regs;
2410ba96fd3SBen Li uint32_t tmp;
2420ba96fd3SBen Li
2430ba96fd3SBen Li ih_regs = &ih->ih_regs;
2440ba96fd3SBen Li
2450ba96fd3SBen Li /* Ring Buffer base. [39:8] of 40-bit address of the beginning of the ring buffer*/
2460ba96fd3SBen Li WREG32(ih_regs->ih_rb_base, ih->gpu_addr >> 8);
2470ba96fd3SBen Li WREG32(ih_regs->ih_rb_base_hi, (ih->gpu_addr >> 40) & 0xff);
2480ba96fd3SBen Li
2490ba96fd3SBen Li tmp = RREG32(ih_regs->ih_rb_cntl);
2500ba96fd3SBen Li tmp = ih_v6_1_rb_cntl(ih, tmp);
2510ba96fd3SBen Li if (ih == &adev->irq.ih)
2520ba96fd3SBen Li tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, RPTR_REARM, !!adev->irq.msi_enabled);
2530ba96fd3SBen Li if (ih == &adev->irq.ih1) {
2540ba96fd3SBen Li tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, WPTR_OVERFLOW_ENABLE, 0);
2550ba96fd3SBen Li tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, RB_FULL_DRAIN_ENABLE, 1);
2560ba96fd3SBen Li }
2570ba96fd3SBen Li
2580ba96fd3SBen Li if (amdgpu_sriov_vf(adev) && amdgpu_sriov_reg_indirect_ih(adev)) {
2590ba96fd3SBen Li if (psp_reg_program(&adev->psp, ih_regs->psp_reg_id, tmp)) {
2600ba96fd3SBen Li DRM_ERROR("PSP program IH_RB_CNTL failed!\n");
2610ba96fd3SBen Li return -ETIMEDOUT;
2620ba96fd3SBen Li }
2630ba96fd3SBen Li } else {
2640ba96fd3SBen Li WREG32(ih_regs->ih_rb_cntl, tmp);
2650ba96fd3SBen Li }
2660ba96fd3SBen Li
2670ba96fd3SBen Li if (ih == &adev->irq.ih) {
2680ba96fd3SBen Li /* set the ih ring 0 writeback address whether it's enabled or not */
2690ba96fd3SBen Li WREG32(ih_regs->ih_rb_wptr_addr_lo, lower_32_bits(ih->wptr_addr));
2700ba96fd3SBen Li WREG32(ih_regs->ih_rb_wptr_addr_hi, upper_32_bits(ih->wptr_addr) & 0xFFFF);
2710ba96fd3SBen Li }
2720ba96fd3SBen Li
2730ba96fd3SBen Li /* set rptr, wptr to 0 */
2740ba96fd3SBen Li WREG32(ih_regs->ih_rb_wptr, 0);
2750ba96fd3SBen Li WREG32(ih_regs->ih_rb_rptr, 0);
2760ba96fd3SBen Li
2770ba96fd3SBen Li WREG32(ih_regs->ih_doorbell_rptr, ih_v6_1_doorbell_rptr(ih));
2780ba96fd3SBen Li
2790ba96fd3SBen Li return 0;
2800ba96fd3SBen Li }
2810ba96fd3SBen Li
2820ba96fd3SBen Li /**
2830ba96fd3SBen Li * ih_v6_1_irq_init - init and enable the interrupt ring
2840ba96fd3SBen Li *
2850ba96fd3SBen Li * @adev: amdgpu_device pointer
2860ba96fd3SBen Li *
2870ba96fd3SBen Li * Allocate a ring buffer for the interrupt controller,
2880ba96fd3SBen Li * enable the RLC, disable interrupts, enable the IH
2890ba96fd3SBen Li * ring buffer and enable it.
2900ba96fd3SBen Li * Called at device load and reume.
2910ba96fd3SBen Li * Returns 0 for success, errors for failure.
2920ba96fd3SBen Li */
ih_v6_1_irq_init(struct amdgpu_device * adev)2930ba96fd3SBen Li static int ih_v6_1_irq_init(struct amdgpu_device *adev)
2940ba96fd3SBen Li {
2950ba96fd3SBen Li struct amdgpu_ih_ring *ih[] = {&adev->irq.ih, &adev->irq.ih1};
2960ba96fd3SBen Li u32 ih_chicken;
2970ba96fd3SBen Li u32 tmp;
2980ba96fd3SBen Li int ret;
2990ba96fd3SBen Li int i;
3000ba96fd3SBen Li
3010ba96fd3SBen Li /* disable irqs */
3020ba96fd3SBen Li ret = ih_v6_1_toggle_interrupts(adev, false);
3030ba96fd3SBen Li if (ret)
3040ba96fd3SBen Li return ret;
3050ba96fd3SBen Li
3060ba96fd3SBen Li adev->nbio.funcs->ih_control(adev);
3070ba96fd3SBen Li
3080ba96fd3SBen Li if (unlikely((adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT) ||
3090ba96fd3SBen Li (adev->firmware.load_type == AMDGPU_FW_LOAD_RLC_BACKDOOR_AUTO))) {
3100ba96fd3SBen Li if (ih[0]->use_bus_addr) {
3110ba96fd3SBen Li ih_chicken = RREG32_SOC15(OSSSYS, 0, regIH_CHICKEN);
3120ba96fd3SBen Li ih_chicken = REG_SET_FIELD(ih_chicken,
3130ba96fd3SBen Li IH_CHICKEN, MC_SPACE_GPA_ENABLE, 1);
3140ba96fd3SBen Li WREG32_SOC15(OSSSYS, 0, regIH_CHICKEN, ih_chicken);
3150ba96fd3SBen Li }
3160ba96fd3SBen Li }
3170ba96fd3SBen Li
3180ba96fd3SBen Li for (i = 0; i < ARRAY_SIZE(ih); i++) {
3190ba96fd3SBen Li if (ih[i]->ring_size) {
3200ba96fd3SBen Li ret = ih_v6_1_enable_ring(adev, ih[i]);
3210ba96fd3SBen Li if (ret)
3220ba96fd3SBen Li return ret;
3230ba96fd3SBen Li }
3240ba96fd3SBen Li }
3250ba96fd3SBen Li
3260ba96fd3SBen Li /* update doorbell range for ih ring 0 */
3270ba96fd3SBen Li adev->nbio.funcs->ih_doorbell_range(adev, ih[0]->use_doorbell,
3280ba96fd3SBen Li ih[0]->doorbell_index);
3290ba96fd3SBen Li
3300ba96fd3SBen Li tmp = RREG32_SOC15(OSSSYS, 0, regIH_STORM_CLIENT_LIST_CNTL);
3310ba96fd3SBen Li tmp = REG_SET_FIELD(tmp, IH_STORM_CLIENT_LIST_CNTL,
3320ba96fd3SBen Li CLIENT18_IS_STORM_CLIENT, 1);
3330ba96fd3SBen Li WREG32_SOC15(OSSSYS, 0, regIH_STORM_CLIENT_LIST_CNTL, tmp);
3340ba96fd3SBen Li
3350ba96fd3SBen Li tmp = RREG32_SOC15(OSSSYS, 0, regIH_INT_FLOOD_CNTL);
3360ba96fd3SBen Li tmp = REG_SET_FIELD(tmp, IH_INT_FLOOD_CNTL, FLOOD_CNTL_ENABLE, 1);
3370ba96fd3SBen Li WREG32_SOC15(OSSSYS, 0, regIH_INT_FLOOD_CNTL, tmp);
3380ba96fd3SBen Li
3390ba96fd3SBen Li /* GC/MMHUB UTCL2 page fault interrupts are configured as
3400ba96fd3SBen Li * MSI storm capable interrupts by deafult. The delay is
3410ba96fd3SBen Li * used to avoid ISR being called too frequently
3420ba96fd3SBen Li * when page fault happens on several continuous page
3430ba96fd3SBen Li * and thus avoid MSI storm */
3440ba96fd3SBen Li tmp = RREG32_SOC15(OSSSYS, 0, regIH_MSI_STORM_CTRL);
3450ba96fd3SBen Li tmp = REG_SET_FIELD(tmp, IH_MSI_STORM_CTRL,
3460ba96fd3SBen Li DELAY, 3);
3470ba96fd3SBen Li WREG32_SOC15(OSSSYS, 0, regIH_MSI_STORM_CTRL, tmp);
3480ba96fd3SBen Li
3490ba96fd3SBen Li pci_set_master(adev->pdev);
3500ba96fd3SBen Li
3510ba96fd3SBen Li /* enable interrupts */
3520ba96fd3SBen Li ret = ih_v6_1_toggle_interrupts(adev, true);
3530ba96fd3SBen Li if (ret)
3540ba96fd3SBen Li return ret;
3550ba96fd3SBen Li /* enable wptr force update for self int */
3560ba96fd3SBen Li force_update_wptr_for_self_int(adev, 0, 8, true);
3570ba96fd3SBen Li
3580ba96fd3SBen Li if (adev->irq.ih_soft.ring_size)
3590ba96fd3SBen Li adev->irq.ih_soft.enabled = true;
3600ba96fd3SBen Li
3610ba96fd3SBen Li return 0;
3620ba96fd3SBen Li }
3630ba96fd3SBen Li
3640ba96fd3SBen Li /**
3650ba96fd3SBen Li * ih_v6_1_irq_disable - disable interrupts
3660ba96fd3SBen Li *
3670ba96fd3SBen Li * @adev: amdgpu_device pointer
3680ba96fd3SBen Li *
3690ba96fd3SBen Li * Disable interrupts on the hw.
3700ba96fd3SBen Li */
ih_v6_1_irq_disable(struct amdgpu_device * adev)3710ba96fd3SBen Li static void ih_v6_1_irq_disable(struct amdgpu_device *adev)
3720ba96fd3SBen Li {
3730ba96fd3SBen Li force_update_wptr_for_self_int(adev, 0, 8, false);
3740ba96fd3SBen Li ih_v6_1_toggle_interrupts(adev, false);
3750ba96fd3SBen Li
3760ba96fd3SBen Li /* Wait and acknowledge irq */
3770ba96fd3SBen Li mdelay(1);
3780ba96fd3SBen Li }
3790ba96fd3SBen Li
3800ba96fd3SBen Li /**
3810ba96fd3SBen Li * ih_v6_1_get_wptr - get the IH ring buffer wptr
3820ba96fd3SBen Li *
3830ba96fd3SBen Li * @adev: amdgpu_device pointer
3840ba96fd3SBen Li * @ih: amdgpu_ih_ring pointer
3850ba96fd3SBen Li *
3860ba96fd3SBen Li * Get the IH ring buffer wptr from either the register
3870ba96fd3SBen Li * or the writeback memory buffer. Also check for
3880ba96fd3SBen Li * ring buffer overflow and deal with it.
3890ba96fd3SBen Li * Returns the value of the wptr.
3900ba96fd3SBen Li */
ih_v6_1_get_wptr(struct amdgpu_device * adev,struct amdgpu_ih_ring * ih)3910ba96fd3SBen Li static u32 ih_v6_1_get_wptr(struct amdgpu_device *adev,
3920ba96fd3SBen Li struct amdgpu_ih_ring *ih)
3930ba96fd3SBen Li {
3940ba96fd3SBen Li u32 wptr, tmp;
3950ba96fd3SBen Li struct amdgpu_ih_regs *ih_regs;
3960ba96fd3SBen Li
3970ba96fd3SBen Li wptr = le32_to_cpu(*ih->wptr_cpu);
3980ba96fd3SBen Li ih_regs = &ih->ih_regs;
3990ba96fd3SBen Li
4000ba96fd3SBen Li if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
4010ba96fd3SBen Li goto out;
4020ba96fd3SBen Li
4030ba96fd3SBen Li wptr = RREG32_NO_KIQ(ih_regs->ih_rb_wptr);
4040ba96fd3SBen Li if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
4050ba96fd3SBen Li goto out;
4060ba96fd3SBen Li wptr = REG_SET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW, 0);
4070ba96fd3SBen Li
4080ba96fd3SBen Li /* When a ring buffer overflow happen start parsing interrupt
4090ba96fd3SBen Li * from the last not overwritten vector (wptr + 32). Hopefully
4100ba96fd3SBen Li * this should allow us to catch up.
4110ba96fd3SBen Li */
4120ba96fd3SBen Li tmp = (wptr + 32) & ih->ptr_mask;
4130ba96fd3SBen Li dev_warn(adev->dev, "IH ring buffer overflow "
4140ba96fd3SBen Li "(0x%08X, 0x%08X, 0x%08X)\n",
4150ba96fd3SBen Li wptr, ih->rptr, tmp);
4160ba96fd3SBen Li ih->rptr = tmp;
4170ba96fd3SBen Li
4180ba96fd3SBen Li tmp = RREG32_NO_KIQ(ih_regs->ih_rb_cntl);
4190ba96fd3SBen Li tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, WPTR_OVERFLOW_CLEAR, 1);
4200ba96fd3SBen Li WREG32_NO_KIQ(ih_regs->ih_rb_cntl, tmp);
421*89833979SFriedrich Vock
422*89833979SFriedrich Vock /* Unset the CLEAR_OVERFLOW bit immediately so new overflows
423*89833979SFriedrich Vock * can be detected.
424*89833979SFriedrich Vock */
425*89833979SFriedrich Vock tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, WPTR_OVERFLOW_CLEAR, 0);
426*89833979SFriedrich Vock WREG32_NO_KIQ(ih_regs->ih_rb_cntl, tmp);
427*89833979SFriedrich Vock
4280ba96fd3SBen Li out:
4290ba96fd3SBen Li return (wptr & ih->ptr_mask);
4300ba96fd3SBen Li }
4310ba96fd3SBen Li
4320ba96fd3SBen Li /**
4330ba96fd3SBen Li * ih_v6_1_irq_rearm - rearm IRQ if lost
4340ba96fd3SBen Li *
4350ba96fd3SBen Li * @adev: amdgpu_device pointer
4360ba96fd3SBen Li * @ih: amdgpu_ih_ring pointer
4370ba96fd3SBen Li *
4380ba96fd3SBen Li */
ih_v6_1_irq_rearm(struct amdgpu_device * adev,struct amdgpu_ih_ring * ih)4390ba96fd3SBen Li static void ih_v6_1_irq_rearm(struct amdgpu_device *adev,
4400ba96fd3SBen Li struct amdgpu_ih_ring *ih)
4410ba96fd3SBen Li {
4420ba96fd3SBen Li uint32_t v = 0;
4430ba96fd3SBen Li uint32_t i = 0;
4440ba96fd3SBen Li struct amdgpu_ih_regs *ih_regs;
4450ba96fd3SBen Li
4460ba96fd3SBen Li ih_regs = &ih->ih_regs;
4470ba96fd3SBen Li
4480ba96fd3SBen Li /* Rearm IRQ / re-write doorbell if doorbell write is lost */
4490ba96fd3SBen Li for (i = 0; i < MAX_REARM_RETRY; i++) {
4500ba96fd3SBen Li v = RREG32_NO_KIQ(ih_regs->ih_rb_rptr);
4510ba96fd3SBen Li if ((v < ih->ring_size) && (v != ih->rptr))
4520ba96fd3SBen Li WDOORBELL32(ih->doorbell_index, ih->rptr);
4530ba96fd3SBen Li else
4540ba96fd3SBen Li break;
4550ba96fd3SBen Li }
4560ba96fd3SBen Li }
4570ba96fd3SBen Li
4580ba96fd3SBen Li /**
4590ba96fd3SBen Li * ih_v6_1_set_rptr - set the IH ring buffer rptr
4600ba96fd3SBen Li *
4610ba96fd3SBen Li * @adev: amdgpu_device pointer
4620ba96fd3SBen Li * @ih: amdgpu_ih_ring pointer
4630ba96fd3SBen Li *
4640ba96fd3SBen Li * Set the IH ring buffer rptr.
4650ba96fd3SBen Li */
ih_v6_1_set_rptr(struct amdgpu_device * adev,struct amdgpu_ih_ring * ih)4660ba96fd3SBen Li static void ih_v6_1_set_rptr(struct amdgpu_device *adev,
4670ba96fd3SBen Li struct amdgpu_ih_ring *ih)
4680ba96fd3SBen Li {
4690ba96fd3SBen Li struct amdgpu_ih_regs *ih_regs;
4700ba96fd3SBen Li
4710ba96fd3SBen Li if (ih->use_doorbell) {
4720ba96fd3SBen Li /* XXX check if swapping is necessary on BE */
4730ba96fd3SBen Li *ih->rptr_cpu = ih->rptr;
4740ba96fd3SBen Li WDOORBELL32(ih->doorbell_index, ih->rptr);
4750ba96fd3SBen Li
4760ba96fd3SBen Li if (amdgpu_sriov_vf(adev))
4770ba96fd3SBen Li ih_v6_1_irq_rearm(adev, ih);
4780ba96fd3SBen Li } else {
4790ba96fd3SBen Li ih_regs = &ih->ih_regs;
4800ba96fd3SBen Li WREG32(ih_regs->ih_rb_rptr, ih->rptr);
4810ba96fd3SBen Li }
4820ba96fd3SBen Li }
4830ba96fd3SBen Li
4840ba96fd3SBen Li /**
4850ba96fd3SBen Li * ih_v6_1_self_irq - dispatch work for ring 1
4860ba96fd3SBen Li *
4870ba96fd3SBen Li * @adev: amdgpu_device pointer
4880ba96fd3SBen Li * @source: irq source
4890ba96fd3SBen Li * @entry: IV with WPTR update
4900ba96fd3SBen Li *
4910ba96fd3SBen Li * Update the WPTR from the IV and schedule work to handle the entries.
4920ba96fd3SBen Li */
ih_v6_1_self_irq(struct amdgpu_device * adev,struct amdgpu_irq_src * source,struct amdgpu_iv_entry * entry)4930ba96fd3SBen Li static int ih_v6_1_self_irq(struct amdgpu_device *adev,
4940ba96fd3SBen Li struct amdgpu_irq_src *source,
4950ba96fd3SBen Li struct amdgpu_iv_entry *entry)
4960ba96fd3SBen Li {
4970ba96fd3SBen Li uint32_t wptr = cpu_to_le32(entry->src_data[0]);
4980ba96fd3SBen Li
4990ba96fd3SBen Li switch (entry->ring_id) {
5000ba96fd3SBen Li case 1:
5010ba96fd3SBen Li *adev->irq.ih1.wptr_cpu = wptr;
5020ba96fd3SBen Li schedule_work(&adev->irq.ih1_work);
5030ba96fd3SBen Li break;
5040ba96fd3SBen Li default:
5050ba96fd3SBen Li break;
5060ba96fd3SBen Li }
5070ba96fd3SBen Li return 0;
5080ba96fd3SBen Li }
5090ba96fd3SBen Li
5100ba96fd3SBen Li static const struct amdgpu_irq_src_funcs ih_v6_1_self_irq_funcs = {
5110ba96fd3SBen Li .process = ih_v6_1_self_irq,
5120ba96fd3SBen Li };
5130ba96fd3SBen Li
ih_v6_1_set_self_irq_funcs(struct amdgpu_device * adev)5140ba96fd3SBen Li static void ih_v6_1_set_self_irq_funcs(struct amdgpu_device *adev)
5150ba96fd3SBen Li {
5160ba96fd3SBen Li adev->irq.self_irq.num_types = 0;
5170ba96fd3SBen Li adev->irq.self_irq.funcs = &ih_v6_1_self_irq_funcs;
5180ba96fd3SBen Li }
5190ba96fd3SBen Li
ih_v6_1_early_init(void * handle)5200ba96fd3SBen Li static int ih_v6_1_early_init(void *handle)
5210ba96fd3SBen Li {
5220ba96fd3SBen Li struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5230ba96fd3SBen Li
5240ba96fd3SBen Li ih_v6_1_set_interrupt_funcs(adev);
5250ba96fd3SBen Li ih_v6_1_set_self_irq_funcs(adev);
5260ba96fd3SBen Li return 0;
5270ba96fd3SBen Li }
5280ba96fd3SBen Li
ih_v6_1_sw_init(void * handle)5290ba96fd3SBen Li static int ih_v6_1_sw_init(void *handle)
5300ba96fd3SBen Li {
5310ba96fd3SBen Li int r;
5320ba96fd3SBen Li struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5330ba96fd3SBen Li bool use_bus_addr;
5340ba96fd3SBen Li
5350ba96fd3SBen Li r = amdgpu_irq_add_id(adev, SOC21_IH_CLIENTID_IH, 0,
5360ba96fd3SBen Li &adev->irq.self_irq);
5370ba96fd3SBen Li
5380ba96fd3SBen Li if (r)
5390ba96fd3SBen Li return r;
5400ba96fd3SBen Li
5410ba96fd3SBen Li /* use gpu virtual address for ih ring
5420ba96fd3SBen Li * until ih_checken is programmed to allow
5430ba96fd3SBen Li * use bus address for ih ring by psp bl */
5440ba96fd3SBen Li use_bus_addr =
5450ba96fd3SBen Li (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) ? false : true;
5460ba96fd3SBen Li r = amdgpu_ih_ring_init(adev, &adev->irq.ih, 256 * 1024, use_bus_addr);
5470ba96fd3SBen Li if (r)
5480ba96fd3SBen Li return r;
5490ba96fd3SBen Li
5500ba96fd3SBen Li adev->irq.ih.use_doorbell = true;
5510ba96fd3SBen Li adev->irq.ih.doorbell_index = adev->doorbell_index.ih << 1;
5520ba96fd3SBen Li
5530ba96fd3SBen Li adev->irq.ih1.ring_size = 0;
5540ba96fd3SBen Li adev->irq.ih2.ring_size = 0;
5550ba96fd3SBen Li
5560ba96fd3SBen Li /* initialize ih control register offset */
5570ba96fd3SBen Li ih_v6_1_init_register_offset(adev);
5580ba96fd3SBen Li
5590ba96fd3SBen Li r = amdgpu_ih_ring_init(adev, &adev->irq.ih_soft, PAGE_SIZE, true);
5600ba96fd3SBen Li if (r)
5610ba96fd3SBen Li return r;
5620ba96fd3SBen Li
5630ba96fd3SBen Li r = amdgpu_irq_init(adev);
5640ba96fd3SBen Li
5650ba96fd3SBen Li return r;
5660ba96fd3SBen Li }
5670ba96fd3SBen Li
ih_v6_1_sw_fini(void * handle)5680ba96fd3SBen Li static int ih_v6_1_sw_fini(void *handle)
5690ba96fd3SBen Li {
5700ba96fd3SBen Li struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5710ba96fd3SBen Li
5720ba96fd3SBen Li amdgpu_irq_fini_sw(adev);
5730ba96fd3SBen Li
5740ba96fd3SBen Li return 0;
5750ba96fd3SBen Li }
5760ba96fd3SBen Li
ih_v6_1_hw_init(void * handle)5770ba96fd3SBen Li static int ih_v6_1_hw_init(void *handle)
5780ba96fd3SBen Li {
5790ba96fd3SBen Li int r;
5800ba96fd3SBen Li struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5810ba96fd3SBen Li
5820ba96fd3SBen Li r = ih_v6_1_irq_init(adev);
5830ba96fd3SBen Li if (r)
5840ba96fd3SBen Li return r;
5850ba96fd3SBen Li
5860ba96fd3SBen Li return 0;
5870ba96fd3SBen Li }
5880ba96fd3SBen Li
ih_v6_1_hw_fini(void * handle)5890ba96fd3SBen Li static int ih_v6_1_hw_fini(void *handle)
5900ba96fd3SBen Li {
5910ba96fd3SBen Li struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5920ba96fd3SBen Li
5930ba96fd3SBen Li ih_v6_1_irq_disable(adev);
5940ba96fd3SBen Li
5950ba96fd3SBen Li return 0;
5960ba96fd3SBen Li }
5970ba96fd3SBen Li
ih_v6_1_suspend(void * handle)5980ba96fd3SBen Li static int ih_v6_1_suspend(void *handle)
5990ba96fd3SBen Li {
6000ba96fd3SBen Li struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6010ba96fd3SBen Li
6020ba96fd3SBen Li return ih_v6_1_hw_fini(adev);
6030ba96fd3SBen Li }
6040ba96fd3SBen Li
ih_v6_1_resume(void * handle)6050ba96fd3SBen Li static int ih_v6_1_resume(void *handle)
6060ba96fd3SBen Li {
6070ba96fd3SBen Li struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6080ba96fd3SBen Li
6090ba96fd3SBen Li return ih_v6_1_hw_init(adev);
6100ba96fd3SBen Li }
6110ba96fd3SBen Li
ih_v6_1_is_idle(void * handle)6120ba96fd3SBen Li static bool ih_v6_1_is_idle(void *handle)
6130ba96fd3SBen Li {
6140ba96fd3SBen Li /* todo */
6150ba96fd3SBen Li return true;
6160ba96fd3SBen Li }
6170ba96fd3SBen Li
ih_v6_1_wait_for_idle(void * handle)6180ba96fd3SBen Li static int ih_v6_1_wait_for_idle(void *handle)
6190ba96fd3SBen Li {
6200ba96fd3SBen Li /* todo */
6210ba96fd3SBen Li return -ETIMEDOUT;
6220ba96fd3SBen Li }
6230ba96fd3SBen Li
ih_v6_1_soft_reset(void * handle)6240ba96fd3SBen Li static int ih_v6_1_soft_reset(void *handle)
6250ba96fd3SBen Li {
6260ba96fd3SBen Li /* todo */
6270ba96fd3SBen Li return 0;
6280ba96fd3SBen Li }
6290ba96fd3SBen Li
ih_v6_1_update_clockgating_state(struct amdgpu_device * adev,bool enable)6300ba96fd3SBen Li static void ih_v6_1_update_clockgating_state(struct amdgpu_device *adev,
6310ba96fd3SBen Li bool enable)
6320ba96fd3SBen Li {
6330ba96fd3SBen Li uint32_t data, def, field_val;
6340ba96fd3SBen Li
6350ba96fd3SBen Li if (adev->cg_flags & AMD_CG_SUPPORT_IH_CG) {
6360ba96fd3SBen Li def = data = RREG32_SOC15(OSSSYS, 0, regIH_CLK_CTRL);
6370ba96fd3SBen Li field_val = enable ? 0 : 1;
6380ba96fd3SBen Li data = REG_SET_FIELD(data, IH_CLK_CTRL,
6390ba96fd3SBen Li DBUS_MUX_CLK_SOFT_OVERRIDE, field_val);
6400ba96fd3SBen Li data = REG_SET_FIELD(data, IH_CLK_CTRL,
6410ba96fd3SBen Li OSSSYS_SHARE_CLK_SOFT_OVERRIDE, field_val);
6420ba96fd3SBen Li data = REG_SET_FIELD(data, IH_CLK_CTRL,
6430ba96fd3SBen Li LIMIT_SMN_CLK_SOFT_OVERRIDE, field_val);
6440ba96fd3SBen Li data = REG_SET_FIELD(data, IH_CLK_CTRL,
6450ba96fd3SBen Li DYN_CLK_SOFT_OVERRIDE, field_val);
6460ba96fd3SBen Li data = REG_SET_FIELD(data, IH_CLK_CTRL,
6470ba96fd3SBen Li REG_CLK_SOFT_OVERRIDE, field_val);
6480ba96fd3SBen Li if (def != data)
6490ba96fd3SBen Li WREG32_SOC15(OSSSYS, 0, regIH_CLK_CTRL, data);
6500ba96fd3SBen Li }
6510ba96fd3SBen Li
6520ba96fd3SBen Li return;
6530ba96fd3SBen Li }
6540ba96fd3SBen Li
ih_v6_1_set_clockgating_state(void * handle,enum amd_clockgating_state state)6550ba96fd3SBen Li static int ih_v6_1_set_clockgating_state(void *handle,
6560ba96fd3SBen Li enum amd_clockgating_state state)
6570ba96fd3SBen Li {
6580ba96fd3SBen Li struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6590ba96fd3SBen Li
6600ba96fd3SBen Li ih_v6_1_update_clockgating_state(adev,
6610ba96fd3SBen Li state == AMD_CG_STATE_GATE);
6620ba96fd3SBen Li return 0;
6630ba96fd3SBen Li }
6640ba96fd3SBen Li
ih_v6_1_update_ih_mem_power_gating(struct amdgpu_device * adev,bool enable)6650ba96fd3SBen Li static void ih_v6_1_update_ih_mem_power_gating(struct amdgpu_device *adev,
6660ba96fd3SBen Li bool enable)
6670ba96fd3SBen Li {
6680ba96fd3SBen Li uint32_t ih_mem_pwr_cntl;
6690ba96fd3SBen Li
6700ba96fd3SBen Li /* Disable ih sram power cntl before switch powergating mode */
6710ba96fd3SBen Li ih_mem_pwr_cntl = RREG32_SOC15(OSSSYS, 0, regIH_MEM_POWER_CTRL);
6720ba96fd3SBen Li ih_mem_pwr_cntl = REG_SET_FIELD(ih_mem_pwr_cntl, IH_MEM_POWER_CTRL,
6730ba96fd3SBen Li IH_BUFFER_MEM_POWER_CTRL_EN, 0);
6740ba96fd3SBen Li WREG32_SOC15(OSSSYS, 0, regIH_MEM_POWER_CTRL, ih_mem_pwr_cntl);
6750ba96fd3SBen Li
6760ba96fd3SBen Li /* It is recommended to set mem powergating mode to DS mode */
6770ba96fd3SBen Li if (enable) {
6780ba96fd3SBen Li /* mem power mode */
6790ba96fd3SBen Li ih_mem_pwr_cntl = REG_SET_FIELD(ih_mem_pwr_cntl, IH_MEM_POWER_CTRL,
6800ba96fd3SBen Li IH_BUFFER_MEM_POWER_LS_EN, 0);
6810ba96fd3SBen Li ih_mem_pwr_cntl = REG_SET_FIELD(ih_mem_pwr_cntl, IH_MEM_POWER_CTRL,
6820ba96fd3SBen Li IH_BUFFER_MEM_POWER_DS_EN, 1);
6830ba96fd3SBen Li ih_mem_pwr_cntl = REG_SET_FIELD(ih_mem_pwr_cntl, IH_MEM_POWER_CTRL,
6840ba96fd3SBen Li IH_BUFFER_MEM_POWER_SD_EN, 0);
6850ba96fd3SBen Li /* cam mem power mode */
6860ba96fd3SBen Li ih_mem_pwr_cntl = REG_SET_FIELD(ih_mem_pwr_cntl, IH_MEM_POWER_CTRL,
6870ba96fd3SBen Li IH_RETRY_INT_CAM_MEM_POWER_LS_EN, 0);
6880ba96fd3SBen Li ih_mem_pwr_cntl = REG_SET_FIELD(ih_mem_pwr_cntl, IH_MEM_POWER_CTRL,
6890ba96fd3SBen Li IH_RETRY_INT_CAM_MEM_POWER_DS_EN, 1);
6900ba96fd3SBen Li ih_mem_pwr_cntl = REG_SET_FIELD(ih_mem_pwr_cntl, IH_MEM_POWER_CTRL,
6910ba96fd3SBen Li IH_RETRY_INT_CAM_MEM_POWER_SD_EN, 0);
6920ba96fd3SBen Li /* re-enable power cntl */
6930ba96fd3SBen Li ih_mem_pwr_cntl = REG_SET_FIELD(ih_mem_pwr_cntl, IH_MEM_POWER_CTRL,
6940ba96fd3SBen Li IH_BUFFER_MEM_POWER_CTRL_EN, 1);
6950ba96fd3SBen Li } else {
6960ba96fd3SBen Li /* mem power mode */
6970ba96fd3SBen Li ih_mem_pwr_cntl = REG_SET_FIELD(ih_mem_pwr_cntl, IH_MEM_POWER_CTRL,
6980ba96fd3SBen Li IH_BUFFER_MEM_POWER_LS_EN, 0);
6990ba96fd3SBen Li ih_mem_pwr_cntl = REG_SET_FIELD(ih_mem_pwr_cntl, IH_MEM_POWER_CTRL,
7000ba96fd3SBen Li IH_BUFFER_MEM_POWER_DS_EN, 0);
7010ba96fd3SBen Li ih_mem_pwr_cntl = REG_SET_FIELD(ih_mem_pwr_cntl, IH_MEM_POWER_CTRL,
7020ba96fd3SBen Li IH_BUFFER_MEM_POWER_SD_EN, 0);
7030ba96fd3SBen Li /* cam mem power mode */
7040ba96fd3SBen Li ih_mem_pwr_cntl = REG_SET_FIELD(ih_mem_pwr_cntl, IH_MEM_POWER_CTRL,
7050ba96fd3SBen Li IH_RETRY_INT_CAM_MEM_POWER_LS_EN, 0);
7060ba96fd3SBen Li ih_mem_pwr_cntl = REG_SET_FIELD(ih_mem_pwr_cntl, IH_MEM_POWER_CTRL,
7070ba96fd3SBen Li IH_RETRY_INT_CAM_MEM_POWER_DS_EN, 0);
7080ba96fd3SBen Li ih_mem_pwr_cntl = REG_SET_FIELD(ih_mem_pwr_cntl, IH_MEM_POWER_CTRL,
7090ba96fd3SBen Li IH_RETRY_INT_CAM_MEM_POWER_SD_EN, 0);
7100ba96fd3SBen Li /* re-enable power cntl*/
7110ba96fd3SBen Li ih_mem_pwr_cntl = REG_SET_FIELD(ih_mem_pwr_cntl, IH_MEM_POWER_CTRL,
7120ba96fd3SBen Li IH_BUFFER_MEM_POWER_CTRL_EN, 1);
7130ba96fd3SBen Li }
7140ba96fd3SBen Li
7150ba96fd3SBen Li WREG32_SOC15(OSSSYS, 0, regIH_MEM_POWER_CTRL, ih_mem_pwr_cntl);
7160ba96fd3SBen Li }
7170ba96fd3SBen Li
ih_v6_1_set_powergating_state(void * handle,enum amd_powergating_state state)7180ba96fd3SBen Li static int ih_v6_1_set_powergating_state(void *handle,
7190ba96fd3SBen Li enum amd_powergating_state state)
7200ba96fd3SBen Li {
7210ba96fd3SBen Li struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7220ba96fd3SBen Li bool enable = (state == AMD_PG_STATE_GATE);
7230ba96fd3SBen Li
7240ba96fd3SBen Li if (adev->pg_flags & AMD_PG_SUPPORT_IH_SRAM_PG)
7250ba96fd3SBen Li ih_v6_1_update_ih_mem_power_gating(adev, enable);
7260ba96fd3SBen Li
7270ba96fd3SBen Li return 0;
7280ba96fd3SBen Li }
7290ba96fd3SBen Li
ih_v6_1_get_clockgating_state(void * handle,u64 * flags)7300ba96fd3SBen Li static void ih_v6_1_get_clockgating_state(void *handle, u64 *flags)
7310ba96fd3SBen Li {
7320ba96fd3SBen Li struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7330ba96fd3SBen Li
7340ba96fd3SBen Li if (!RREG32_SOC15(OSSSYS, 0, regIH_CLK_CTRL))
7350ba96fd3SBen Li *flags |= AMD_CG_SUPPORT_IH_CG;
7360ba96fd3SBen Li
7370ba96fd3SBen Li return;
7380ba96fd3SBen Li }
7390ba96fd3SBen Li
7400ba96fd3SBen Li static const struct amd_ip_funcs ih_v6_1_ip_funcs = {
7410ba96fd3SBen Li .name = "ih_v6_1",
7420ba96fd3SBen Li .early_init = ih_v6_1_early_init,
7430ba96fd3SBen Li .late_init = NULL,
7440ba96fd3SBen Li .sw_init = ih_v6_1_sw_init,
7450ba96fd3SBen Li .sw_fini = ih_v6_1_sw_fini,
7460ba96fd3SBen Li .hw_init = ih_v6_1_hw_init,
7470ba96fd3SBen Li .hw_fini = ih_v6_1_hw_fini,
7480ba96fd3SBen Li .suspend = ih_v6_1_suspend,
7490ba96fd3SBen Li .resume = ih_v6_1_resume,
7500ba96fd3SBen Li .is_idle = ih_v6_1_is_idle,
7510ba96fd3SBen Li .wait_for_idle = ih_v6_1_wait_for_idle,
7520ba96fd3SBen Li .soft_reset = ih_v6_1_soft_reset,
7530ba96fd3SBen Li .set_clockgating_state = ih_v6_1_set_clockgating_state,
7540ba96fd3SBen Li .set_powergating_state = ih_v6_1_set_powergating_state,
7550ba96fd3SBen Li .get_clockgating_state = ih_v6_1_get_clockgating_state,
7560ba96fd3SBen Li };
7570ba96fd3SBen Li
7580ba96fd3SBen Li static const struct amdgpu_ih_funcs ih_v6_1_funcs = {
7590ba96fd3SBen Li .get_wptr = ih_v6_1_get_wptr,
7600ba96fd3SBen Li .decode_iv = amdgpu_ih_decode_iv_helper,
7610ba96fd3SBen Li .decode_iv_ts = amdgpu_ih_decode_iv_ts_helper,
7620ba96fd3SBen Li .set_rptr = ih_v6_1_set_rptr
7630ba96fd3SBen Li };
7640ba96fd3SBen Li
ih_v6_1_set_interrupt_funcs(struct amdgpu_device * adev)7650ba96fd3SBen Li static void ih_v6_1_set_interrupt_funcs(struct amdgpu_device *adev)
7660ba96fd3SBen Li {
7670ba96fd3SBen Li adev->irq.ih_funcs = &ih_v6_1_funcs;
7680ba96fd3SBen Li }
7690ba96fd3SBen Li
7700ba96fd3SBen Li const struct amdgpu_ip_block_version ih_v6_1_ip_block = {
7710ba96fd3SBen Li .type = AMD_IP_BLOCK_TYPE_IH,
7720ba96fd3SBen Li .major = 6,
7730ba96fd3SBen Li .minor = 0,
7740ba96fd3SBen Li .rev = 0,
7750ba96fd3SBen Li .funcs = &ih_v6_1_ip_funcs,
7760ba96fd3SBen Li };
777