1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2020-2023 Intel Corporation
9 #include "ivpu_hw_40xx_reg.h"
10 #include "ivpu_hw_reg_io.h"
15 #include <linux/dmi.h>
17 #define TILE_MAX_NUM 6
18 #define TILE_MAX_MASK 0x3f
20 #define LNL_HW_ID 0x4040
22 #define SKU_TILE_SHIFT 0u
23 #define SKU_TILE_MASK 0x0000ffffu
24 #define SKU_HW_ID_SHIFT 16u
25 #define SKU_HW_ID_MASK 0xffff0000u
27 #define PLL_CONFIG_DEFAULT 0x1
28 #define PLL_CDYN_DEFAULT 0x80
29 #define PLL_EPP_DEFAULT 0x80
30 #define PLL_REF_CLK_FREQ (50 * 1000000)
31 #define PLL_RATIO_TO_FREQ(x) ((x) * PLL_REF_CLK_FREQ)
33 #define PLL_PROFILING_FREQ_DEFAULT 38400000
34 #define PLL_PROFILING_FREQ_HIGH 400000000
36 #define TIM_SAFE_ENABLE 0xf1d0dead
37 #define TIM_WATCHDOG_RESET_VALUE 0xffffffff
39 #define TIMEOUT_US (150 * USEC_PER_MSEC)
40 #define PWR_ISLAND_STATUS_TIMEOUT_US (5 * USEC_PER_MSEC)
41 #define PLL_TIMEOUT_US (1500 * USEC_PER_MSEC)
43 #define WEIGHTS_DEFAULT 0xf711f711u
44 #define WEIGHTS_ATS_DEFAULT 0x0000f711u
46 #define ICB_0_IRQ_MASK ((REG_FLD(VPU_40XX_HOST_SS_ICB_STATUS_0, HOST_IPC_FIFO_INT)) | \
47 (REG_FLD(VPU_40XX_HOST_SS_ICB_STATUS_0, MMU_IRQ_0_INT)) | \
48 (REG_FLD(VPU_40XX_HOST_SS_ICB_STATUS_0, MMU_IRQ_1_INT)) | \
49 (REG_FLD(VPU_40XX_HOST_SS_ICB_STATUS_0, MMU_IRQ_2_INT)) | \
50 (REG_FLD(VPU_40XX_HOST_SS_ICB_STATUS_0, NOC_FIREWALL_INT)) | \
51 (REG_FLD(VPU_40XX_HOST_SS_ICB_STATUS_0, CPU_INT_REDIRECT_0_INT)) | \
52 (REG_FLD(VPU_40XX_HOST_SS_ICB_STATUS_0, CPU_INT_REDIRECT_1_INT)))
54 #define ICB_1_IRQ_MASK ((REG_FLD(VPU_40XX_HOST_SS_ICB_STATUS_1, CPU_INT_REDIRECT_2_INT)) | \
55 (REG_FLD(VPU_40XX_HOST_SS_ICB_STATUS_1, CPU_INT_REDIRECT_3_INT)) | \
56 (REG_FLD(VPU_40XX_HOST_SS_ICB_STATUS_1, CPU_INT_REDIRECT_4_INT)))
58 #define ICB_0_1_IRQ_MASK ((((u64)ICB_1_IRQ_MASK) << 32) | ICB_0_IRQ_MASK)
60 #define BUTTRESS_IRQ_MASK ((REG_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, FREQ_CHANGE)) | \
61 (REG_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, ATS_ERR)) | \
62 (REG_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, CFI0_ERR)) | \
63 (REG_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, CFI1_ERR)) | \
64 (REG_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, IMR0_ERR)) | \
65 (REG_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, IMR1_ERR)) | \
66 (REG_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, SURV_ERR)))
68 #define BUTTRESS_IRQ_ENABLE_MASK ((u32)~BUTTRESS_IRQ_MASK)
69 #define BUTTRESS_IRQ_DISABLE_MASK ((u32)-1)
71 #define ITF_FIREWALL_VIOLATION_MASK ((REG_FLD(VPU_40XX_HOST_SS_FW_SOC_IRQ_EN, CSS_ROM_CMX)) | \
72 (REG_FLD(VPU_40XX_HOST_SS_FW_SOC_IRQ_EN, CSS_DBG)) | \
73 (REG_FLD(VPU_40XX_HOST_SS_FW_SOC_IRQ_EN, CSS_CTRL)) | \
74 (REG_FLD(VPU_40XX_HOST_SS_FW_SOC_IRQ_EN, DEC400)) | \
75 (REG_FLD(VPU_40XX_HOST_SS_FW_SOC_IRQ_EN, MSS_NCE)) | \
76 (REG_FLD(VPU_40XX_HOST_SS_FW_SOC_IRQ_EN, MSS_MBI)) | \
77 (REG_FLD(VPU_40XX_HOST_SS_FW_SOC_IRQ_EN, MSS_MBI_CMX)))
79 static char *ivpu_platform_to_str(u32 platform)
82 case IVPU_PLATFORM_SILICON:
83 return "IVPU_PLATFORM_SILICON";
84 case IVPU_PLATFORM_SIMICS:
85 return "IVPU_PLATFORM_SIMICS";
86 case IVPU_PLATFORM_FPGA:
87 return "IVPU_PLATFORM_FPGA";
89 return "Invalid platform";
93 static const struct dmi_system_id ivpu_dmi_platform_simulation[] = {
95 .ident = "Intel Simics",
97 DMI_MATCH(DMI_BOARD_NAME, "lnlrvp"),
98 DMI_MATCH(DMI_BOARD_VERSION, "1.0"),
99 DMI_MATCH(DMI_BOARD_SERIAL, "123456789"),
103 .ident = "Intel Simics",
105 DMI_MATCH(DMI_BOARD_NAME, "Simics"),
111 static void ivpu_hw_read_platform(struct ivpu_device *vdev)
113 if (dmi_check_system(ivpu_dmi_platform_simulation))
114 vdev->platform = IVPU_PLATFORM_SIMICS;
116 vdev->platform = IVPU_PLATFORM_SILICON;
118 ivpu_dbg(vdev, MISC, "Platform type: %s (%d)\n",
119 ivpu_platform_to_str(vdev->platform), vdev->platform);
122 static void ivpu_hw_wa_init(struct ivpu_device *vdev)
124 vdev->wa.punit_disabled = ivpu_is_fpga(vdev);
125 vdev->wa.clear_runtime_mem = false;
127 if (ivpu_hw_gen(vdev) == IVPU_HW_40XX)
128 vdev->wa.disable_clock_relinquish = true;
131 static void ivpu_hw_timeouts_init(struct ivpu_device *vdev)
133 if (ivpu_is_fpga(vdev)) {
134 vdev->timeout.boot = 100000;
135 vdev->timeout.jsm = 50000;
136 vdev->timeout.tdr = 2000000;
137 vdev->timeout.reschedule_suspend = 1000;
138 } else if (ivpu_is_simics(vdev)) {
139 vdev->timeout.boot = 50;
140 vdev->timeout.jsm = 500;
141 vdev->timeout.tdr = 10000;
142 vdev->timeout.reschedule_suspend = 10;
144 vdev->timeout.boot = 1000;
145 vdev->timeout.jsm = 500;
146 vdev->timeout.tdr = 2000;
147 vdev->timeout.reschedule_suspend = 10;
151 static int ivpu_pll_wait_for_cmd_send(struct ivpu_device *vdev)
153 return REGB_POLL_FLD(VPU_40XX_BUTTRESS_WP_REQ_CMD, SEND, 0, PLL_TIMEOUT_US);
156 static int ivpu_pll_cmd_send(struct ivpu_device *vdev, u16 min_ratio, u16 max_ratio,
157 u16 target_ratio, u16 epp, u16 config, u16 cdyn)
162 ret = ivpu_pll_wait_for_cmd_send(vdev);
164 ivpu_err(vdev, "Failed to sync before WP request: %d\n", ret);
168 val = REGB_RD32(VPU_40XX_BUTTRESS_WP_REQ_PAYLOAD0);
169 val = REG_SET_FLD_NUM(VPU_40XX_BUTTRESS_WP_REQ_PAYLOAD0, MIN_RATIO, min_ratio, val);
170 val = REG_SET_FLD_NUM(VPU_40XX_BUTTRESS_WP_REQ_PAYLOAD0, MAX_RATIO, max_ratio, val);
171 REGB_WR32(VPU_40XX_BUTTRESS_WP_REQ_PAYLOAD0, val);
173 val = REGB_RD32(VPU_40XX_BUTTRESS_WP_REQ_PAYLOAD1);
174 val = REG_SET_FLD_NUM(VPU_40XX_BUTTRESS_WP_REQ_PAYLOAD1, TARGET_RATIO, target_ratio, val);
175 val = REG_SET_FLD_NUM(VPU_40XX_BUTTRESS_WP_REQ_PAYLOAD1, EPP, epp, val);
176 REGB_WR32(VPU_40XX_BUTTRESS_WP_REQ_PAYLOAD1, val);
178 val = REGB_RD32(VPU_40XX_BUTTRESS_WP_REQ_PAYLOAD2);
179 val = REG_SET_FLD_NUM(VPU_40XX_BUTTRESS_WP_REQ_PAYLOAD2, CONFIG, config, val);
180 val = REG_SET_FLD_NUM(VPU_40XX_BUTTRESS_WP_REQ_PAYLOAD2, CDYN, cdyn, val);
181 REGB_WR32(VPU_40XX_BUTTRESS_WP_REQ_PAYLOAD2, val);
183 val = REGB_RD32(VPU_40XX_BUTTRESS_WP_REQ_CMD);
184 val = REG_SET_FLD(VPU_40XX_BUTTRESS_WP_REQ_CMD, SEND, val);
185 REGB_WR32(VPU_40XX_BUTTRESS_WP_REQ_CMD, val);
187 ret = ivpu_pll_wait_for_cmd_send(vdev);
189 ivpu_err(vdev, "Failed to sync after WP request: %d\n", ret);
194 static int ivpu_pll_wait_for_status_ready(struct ivpu_device *vdev)
196 return REGB_POLL_FLD(VPU_40XX_BUTTRESS_VPU_STATUS, READY, 1, PLL_TIMEOUT_US);
199 static void ivpu_pll_init_frequency_ratios(struct ivpu_device *vdev)
201 struct ivpu_hw_info *hw = vdev->hw;
202 u8 fuse_min_ratio, fuse_pn_ratio, fuse_max_ratio;
203 u32 fmin_fuse, fmax_fuse;
205 fmin_fuse = REGB_RD32(VPU_40XX_BUTTRESS_FMIN_FUSE);
206 fuse_min_ratio = REG_GET_FLD(VPU_40XX_BUTTRESS_FMIN_FUSE, MIN_RATIO, fmin_fuse);
207 fuse_pn_ratio = REG_GET_FLD(VPU_40XX_BUTTRESS_FMIN_FUSE, PN_RATIO, fmin_fuse);
209 fmax_fuse = REGB_RD32(VPU_40XX_BUTTRESS_FMAX_FUSE);
210 fuse_max_ratio = REG_GET_FLD(VPU_40XX_BUTTRESS_FMAX_FUSE, MAX_RATIO, fmax_fuse);
212 hw->pll.min_ratio = clamp_t(u8, ivpu_pll_min_ratio, fuse_min_ratio, fuse_max_ratio);
213 hw->pll.max_ratio = clamp_t(u8, ivpu_pll_max_ratio, hw->pll.min_ratio, fuse_max_ratio);
214 hw->pll.pn_ratio = clamp_t(u8, fuse_pn_ratio, hw->pll.min_ratio, hw->pll.max_ratio);
217 static int ivpu_pll_drive(struct ivpu_device *vdev, bool enable)
219 u16 config = enable ? PLL_CONFIG_DEFAULT : 0;
220 u16 cdyn = enable ? PLL_CDYN_DEFAULT : 0;
221 u16 epp = enable ? PLL_EPP_DEFAULT : 0;
222 struct ivpu_hw_info *hw = vdev->hw;
223 u16 target_ratio = hw->pll.pn_ratio;
226 ivpu_dbg(vdev, PM, "PLL workpoint request: %u Hz, epp: 0x%x, config: 0x%x, cdyn: 0x%x\n",
227 PLL_RATIO_TO_FREQ(target_ratio), epp, config, cdyn);
229 ret = ivpu_pll_cmd_send(vdev, hw->pll.min_ratio, hw->pll.max_ratio,
230 target_ratio, epp, config, cdyn);
232 ivpu_err(vdev, "Failed to send PLL workpoint request: %d\n", ret);
237 ret = ivpu_pll_wait_for_status_ready(vdev);
239 ivpu_err(vdev, "Timed out waiting for PLL ready status\n");
247 static int ivpu_pll_enable(struct ivpu_device *vdev)
249 return ivpu_pll_drive(vdev, true);
252 static int ivpu_pll_disable(struct ivpu_device *vdev)
254 return ivpu_pll_drive(vdev, false);
257 static void ivpu_boot_host_ss_rst_drive(struct ivpu_device *vdev, bool enable)
259 u32 val = REGV_RD32(VPU_40XX_HOST_SS_CPR_RST_EN);
262 val = REG_SET_FLD(VPU_40XX_HOST_SS_CPR_RST_EN, TOP_NOC, val);
263 val = REG_SET_FLD(VPU_40XX_HOST_SS_CPR_RST_EN, DSS_MAS, val);
264 val = REG_SET_FLD(VPU_40XX_HOST_SS_CPR_RST_EN, CSS_MAS, val);
266 val = REG_CLR_FLD(VPU_40XX_HOST_SS_CPR_RST_EN, TOP_NOC, val);
267 val = REG_CLR_FLD(VPU_40XX_HOST_SS_CPR_RST_EN, DSS_MAS, val);
268 val = REG_CLR_FLD(VPU_40XX_HOST_SS_CPR_RST_EN, CSS_MAS, val);
271 REGV_WR32(VPU_40XX_HOST_SS_CPR_RST_EN, val);
274 static void ivpu_boot_host_ss_clk_drive(struct ivpu_device *vdev, bool enable)
276 u32 val = REGV_RD32(VPU_40XX_HOST_SS_CPR_CLK_EN);
279 val = REG_SET_FLD(VPU_40XX_HOST_SS_CPR_CLK_EN, TOP_NOC, val);
280 val = REG_SET_FLD(VPU_40XX_HOST_SS_CPR_CLK_EN, DSS_MAS, val);
281 val = REG_SET_FLD(VPU_40XX_HOST_SS_CPR_CLK_EN, CSS_MAS, val);
283 val = REG_CLR_FLD(VPU_40XX_HOST_SS_CPR_CLK_EN, TOP_NOC, val);
284 val = REG_CLR_FLD(VPU_40XX_HOST_SS_CPR_CLK_EN, DSS_MAS, val);
285 val = REG_CLR_FLD(VPU_40XX_HOST_SS_CPR_CLK_EN, CSS_MAS, val);
288 REGV_WR32(VPU_40XX_HOST_SS_CPR_CLK_EN, val);
291 static int ivpu_boot_noc_qreqn_check(struct ivpu_device *vdev, u32 exp_val)
293 u32 val = REGV_RD32(VPU_40XX_HOST_SS_NOC_QREQN);
295 if (!REG_TEST_FLD_NUM(VPU_40XX_HOST_SS_NOC_QREQN, TOP_SOCMMIO, exp_val, val))
301 static int ivpu_boot_noc_qacceptn_check(struct ivpu_device *vdev, u32 exp_val)
303 u32 val = REGV_RD32(VPU_40XX_HOST_SS_NOC_QACCEPTN);
305 if (!REG_TEST_FLD_NUM(VPU_40XX_HOST_SS_NOC_QACCEPTN, TOP_SOCMMIO, exp_val, val))
311 static int ivpu_boot_noc_qdeny_check(struct ivpu_device *vdev, u32 exp_val)
313 u32 val = REGV_RD32(VPU_40XX_HOST_SS_NOC_QDENY);
315 if (!REG_TEST_FLD_NUM(VPU_40XX_HOST_SS_NOC_QDENY, TOP_SOCMMIO, exp_val, val))
321 static int ivpu_boot_top_noc_qrenqn_check(struct ivpu_device *vdev, u32 exp_val)
323 u32 val = REGV_RD32(VPU_40XX_TOP_NOC_QREQN);
325 if (!REG_TEST_FLD_NUM(VPU_40XX_TOP_NOC_QREQN, CPU_CTRL, exp_val, val) ||
326 !REG_TEST_FLD_NUM(VPU_40XX_TOP_NOC_QREQN, HOSTIF_L2CACHE, exp_val, val))
332 static int ivpu_boot_top_noc_qacceptn_check(struct ivpu_device *vdev, u32 exp_val)
334 u32 val = REGV_RD32(VPU_40XX_TOP_NOC_QACCEPTN);
336 if (!REG_TEST_FLD_NUM(VPU_40XX_TOP_NOC_QACCEPTN, CPU_CTRL, exp_val, val) ||
337 !REG_TEST_FLD_NUM(VPU_40XX_TOP_NOC_QACCEPTN, HOSTIF_L2CACHE, exp_val, val))
343 static int ivpu_boot_top_noc_qdeny_check(struct ivpu_device *vdev, u32 exp_val)
345 u32 val = REGV_RD32(VPU_40XX_TOP_NOC_QDENY);
347 if (!REG_TEST_FLD_NUM(VPU_40XX_TOP_NOC_QDENY, CPU_CTRL, exp_val, val) ||
348 !REG_TEST_FLD_NUM(VPU_40XX_TOP_NOC_QDENY, HOSTIF_L2CACHE, exp_val, val))
354 static void ivpu_boot_idle_gen_drive(struct ivpu_device *vdev, bool enable)
356 u32 val = REGV_RD32(VPU_40XX_HOST_SS_AON_IDLE_GEN);
359 val = REG_SET_FLD(VPU_40XX_HOST_SS_AON_IDLE_GEN, EN, val);
361 val = REG_CLR_FLD(VPU_40XX_HOST_SS_AON_IDLE_GEN, EN, val);
363 REGV_WR32(VPU_40XX_HOST_SS_AON_IDLE_GEN, val);
366 static int ivpu_boot_host_ss_check(struct ivpu_device *vdev)
370 ret = ivpu_boot_noc_qreqn_check(vdev, 0x0);
372 ivpu_err(vdev, "Failed qreqn check: %d\n", ret);
376 ret = ivpu_boot_noc_qacceptn_check(vdev, 0x0);
378 ivpu_err(vdev, "Failed qacceptn check: %d\n", ret);
382 ret = ivpu_boot_noc_qdeny_check(vdev, 0x0);
384 ivpu_err(vdev, "Failed qdeny check %d\n", ret);
389 static int ivpu_boot_host_ss_axi_drive(struct ivpu_device *vdev, bool enable)
394 val = REGV_RD32(VPU_40XX_HOST_SS_NOC_QREQN);
396 val = REG_SET_FLD(VPU_40XX_HOST_SS_NOC_QREQN, TOP_SOCMMIO, val);
398 val = REG_CLR_FLD(VPU_40XX_HOST_SS_NOC_QREQN, TOP_SOCMMIO, val);
399 REGV_WR32(VPU_40XX_HOST_SS_NOC_QREQN, val);
401 ret = ivpu_boot_noc_qacceptn_check(vdev, enable ? 0x1 : 0x0);
403 ivpu_err(vdev, "Failed qacceptn check: %d\n", ret);
407 ret = ivpu_boot_noc_qdeny_check(vdev, 0x0);
409 ivpu_err(vdev, "Failed qdeny check: %d\n", ret);
414 REGB_WR32(VPU_40XX_BUTTRESS_PORT_ARBITRATION_WEIGHTS, WEIGHTS_DEFAULT);
415 REGB_WR32(VPU_40XX_BUTTRESS_PORT_ARBITRATION_WEIGHTS_ATS, WEIGHTS_ATS_DEFAULT);
421 static int ivpu_boot_host_ss_axi_enable(struct ivpu_device *vdev)
423 return ivpu_boot_host_ss_axi_drive(vdev, true);
426 static int ivpu_boot_host_ss_top_noc_drive(struct ivpu_device *vdev, bool enable)
431 val = REGV_RD32(VPU_40XX_TOP_NOC_QREQN);
433 val = REG_SET_FLD(VPU_40XX_TOP_NOC_QREQN, CPU_CTRL, val);
434 val = REG_SET_FLD(VPU_40XX_TOP_NOC_QREQN, HOSTIF_L2CACHE, val);
436 val = REG_CLR_FLD(VPU_40XX_TOP_NOC_QREQN, CPU_CTRL, val);
437 val = REG_CLR_FLD(VPU_40XX_TOP_NOC_QREQN, HOSTIF_L2CACHE, val);
439 REGV_WR32(VPU_40XX_TOP_NOC_QREQN, val);
441 ret = ivpu_boot_top_noc_qacceptn_check(vdev, enable ? 0x1 : 0x0);
443 ivpu_err(vdev, "Failed qacceptn check: %d\n", ret);
447 ret = ivpu_boot_top_noc_qdeny_check(vdev, 0x0);
449 ivpu_err(vdev, "Failed qdeny check: %d\n", ret);
454 static int ivpu_boot_host_ss_top_noc_enable(struct ivpu_device *vdev)
456 return ivpu_boot_host_ss_top_noc_drive(vdev, true);
459 static void ivpu_boot_pwr_island_trickle_drive(struct ivpu_device *vdev, bool enable)
461 u32 val = REGV_RD32(VPU_40XX_HOST_SS_AON_PWR_ISLAND_TRICKLE_EN0);
464 val = REG_SET_FLD(VPU_40XX_HOST_SS_AON_PWR_ISLAND_TRICKLE_EN0, CSS_CPU, val);
466 val = REG_CLR_FLD(VPU_40XX_HOST_SS_AON_PWR_ISLAND_TRICKLE_EN0, CSS_CPU, val);
468 REGV_WR32(VPU_40XX_HOST_SS_AON_PWR_ISLAND_TRICKLE_EN0, val);
474 static void ivpu_boot_pwr_island_drive(struct ivpu_device *vdev, bool enable)
476 u32 val = REGV_RD32(VPU_40XX_HOST_SS_AON_PWR_ISLAND_EN0);
479 val = REG_SET_FLD(VPU_40XX_HOST_SS_AON_PWR_ISLAND_EN0, CSS_CPU, val);
481 val = REG_CLR_FLD(VPU_40XX_HOST_SS_AON_PWR_ISLAND_EN0, CSS_CPU, val);
483 REGV_WR32(VPU_40XX_HOST_SS_AON_PWR_ISLAND_EN0, val);
489 static int ivpu_boot_wait_for_pwr_island_status(struct ivpu_device *vdev, u32 exp_val)
491 if (ivpu_is_fpga(vdev))
494 return REGV_POLL_FLD(VPU_40XX_HOST_SS_AON_PWR_ISLAND_STATUS0, CSS_CPU,
495 exp_val, PWR_ISLAND_STATUS_TIMEOUT_US);
498 static void ivpu_boot_pwr_island_isolation_drive(struct ivpu_device *vdev, bool enable)
500 u32 val = REGV_RD32(VPU_40XX_HOST_SS_AON_PWR_ISO_EN0);
503 val = REG_SET_FLD(VPU_40XX_HOST_SS_AON_PWR_ISO_EN0, CSS_CPU, val);
505 val = REG_CLR_FLD(VPU_40XX_HOST_SS_AON_PWR_ISO_EN0, CSS_CPU, val);
507 REGV_WR32(VPU_40XX_HOST_SS_AON_PWR_ISO_EN0, val);
510 static void ivpu_boot_no_snoop_enable(struct ivpu_device *vdev)
512 u32 val = REGV_RD32(VPU_40XX_HOST_IF_TCU_PTW_OVERRIDES);
514 val = REG_SET_FLD(VPU_40XX_HOST_IF_TCU_PTW_OVERRIDES, SNOOP_OVERRIDE_EN, val);
515 val = REG_CLR_FLD(VPU_40XX_HOST_IF_TCU_PTW_OVERRIDES, AW_SNOOP_OVERRIDE, val);
516 val = REG_CLR_FLD(VPU_40XX_HOST_IF_TCU_PTW_OVERRIDES, AR_SNOOP_OVERRIDE, val);
518 REGV_WR32(VPU_40XX_HOST_IF_TCU_PTW_OVERRIDES, val);
521 static void ivpu_boot_tbu_mmu_enable(struct ivpu_device *vdev)
523 u32 val = REGV_RD32(VPU_40XX_HOST_IF_TBU_MMUSSIDV);
525 val = REG_SET_FLD(VPU_40XX_HOST_IF_TBU_MMUSSIDV, TBU0_AWMMUSSIDV, val);
526 val = REG_SET_FLD(VPU_40XX_HOST_IF_TBU_MMUSSIDV, TBU0_ARMMUSSIDV, val);
527 val = REG_SET_FLD(VPU_40XX_HOST_IF_TBU_MMUSSIDV, TBU1_AWMMUSSIDV, val);
528 val = REG_SET_FLD(VPU_40XX_HOST_IF_TBU_MMUSSIDV, TBU1_ARMMUSSIDV, val);
529 val = REG_SET_FLD(VPU_40XX_HOST_IF_TBU_MMUSSIDV, TBU2_AWMMUSSIDV, val);
530 val = REG_SET_FLD(VPU_40XX_HOST_IF_TBU_MMUSSIDV, TBU2_ARMMUSSIDV, val);
532 REGV_WR32(VPU_40XX_HOST_IF_TBU_MMUSSIDV, val);
535 static int ivpu_boot_cpu_noc_qacceptn_check(struct ivpu_device *vdev, u32 exp_val)
537 u32 val = REGV_RD32(VPU_40XX_CPU_SS_CPR_NOC_QACCEPTN);
539 if (!REG_TEST_FLD_NUM(VPU_40XX_CPU_SS_CPR_NOC_QACCEPTN, TOP_MMIO, exp_val, val))
545 static int ivpu_boot_cpu_noc_qdeny_check(struct ivpu_device *vdev, u32 exp_val)
547 u32 val = REGV_RD32(VPU_40XX_CPU_SS_CPR_NOC_QDENY);
549 if (!REG_TEST_FLD_NUM(VPU_40XX_CPU_SS_CPR_NOC_QDENY, TOP_MMIO, exp_val, val))
555 static int ivpu_boot_pwr_domain_enable(struct ivpu_device *vdev)
559 ivpu_boot_pwr_island_trickle_drive(vdev, true);
560 ivpu_boot_pwr_island_drive(vdev, true);
562 ret = ivpu_boot_wait_for_pwr_island_status(vdev, 0x1);
564 ivpu_err(vdev, "Timed out waiting for power island status\n");
568 ret = ivpu_boot_top_noc_qrenqn_check(vdev, 0x0);
570 ivpu_err(vdev, "Failed qrenqn check %d\n", ret);
574 ivpu_boot_host_ss_clk_drive(vdev, true);
575 ivpu_boot_host_ss_rst_drive(vdev, true);
576 ivpu_boot_pwr_island_isolation_drive(vdev, false);
581 static int ivpu_boot_soc_cpu_drive(struct ivpu_device *vdev, bool enable)
586 val = REGV_RD32(VPU_40XX_CPU_SS_CPR_NOC_QREQN);
588 val = REG_SET_FLD(VPU_40XX_CPU_SS_CPR_NOC_QREQN, TOP_MMIO, val);
590 val = REG_CLR_FLD(VPU_40XX_CPU_SS_CPR_NOC_QREQN, TOP_MMIO, val);
591 REGV_WR32(VPU_40XX_CPU_SS_CPR_NOC_QREQN, val);
593 ret = ivpu_boot_cpu_noc_qacceptn_check(vdev, enable ? 0x1 : 0x0);
595 ivpu_err(vdev, "Failed qacceptn check: %d\n", ret);
599 ret = ivpu_boot_cpu_noc_qdeny_check(vdev, 0x0);
601 ivpu_err(vdev, "Failed qdeny check: %d\n", ret);
606 static int ivpu_boot_soc_cpu_enable(struct ivpu_device *vdev)
608 return ivpu_boot_soc_cpu_drive(vdev, true);
611 static int ivpu_boot_soc_cpu_boot(struct ivpu_device *vdev)
617 ret = ivpu_boot_soc_cpu_enable(vdev);
619 ivpu_err(vdev, "Failed to enable SOC CPU: %d\n", ret);
623 val64 = vdev->fw->entry_point;
624 val64 <<= ffs(VPU_40XX_HOST_SS_VERIFICATION_ADDRESS_LO_IMAGE_LOCATION_MASK) - 1;
625 REGV_WR64(VPU_40XX_HOST_SS_VERIFICATION_ADDRESS_LO, val64);
627 val = REGV_RD32(VPU_40XX_HOST_SS_VERIFICATION_ADDRESS_LO);
628 val = REG_SET_FLD(VPU_40XX_HOST_SS_VERIFICATION_ADDRESS_LO, DONE, val);
629 REGV_WR32(VPU_40XX_HOST_SS_VERIFICATION_ADDRESS_LO, val);
631 ivpu_dbg(vdev, PM, "Booting firmware, mode: %s\n",
632 ivpu_fw_is_cold_boot(vdev) ? "cold boot" : "resume");
637 static int ivpu_boot_d0i3_drive(struct ivpu_device *vdev, bool enable)
642 ret = REGB_POLL_FLD(VPU_40XX_BUTTRESS_D0I3_CONTROL, INPROGRESS, 0, TIMEOUT_US);
644 ivpu_err(vdev, "Failed to sync before D0i3 transition: %d\n", ret);
648 val = REGB_RD32(VPU_40XX_BUTTRESS_D0I3_CONTROL);
650 val = REG_SET_FLD(VPU_40XX_BUTTRESS_D0I3_CONTROL, I3, val);
652 val = REG_CLR_FLD(VPU_40XX_BUTTRESS_D0I3_CONTROL, I3, val);
653 REGB_WR32(VPU_40XX_BUTTRESS_D0I3_CONTROL, val);
655 ret = REGB_POLL_FLD(VPU_40XX_BUTTRESS_D0I3_CONTROL, INPROGRESS, 0, TIMEOUT_US);
657 ivpu_err(vdev, "Failed to sync after D0i3 transition: %d\n", ret);
664 static bool ivpu_tile_disable_check(u32 config)
666 /* Allowed values: 0 or one bit from range 0-5 (6 tiles) */
670 if (config > BIT(TILE_MAX_NUM - 1))
673 if ((config & (config - 1)) == 0)
679 static int ivpu_hw_40xx_info_init(struct ivpu_device *vdev)
681 struct ivpu_hw_info *hw = vdev->hw;
686 fuse = REGB_RD32(VPU_40XX_BUTTRESS_TILE_FUSE);
687 if (!REG_TEST_FLD(VPU_40XX_BUTTRESS_TILE_FUSE, VALID, fuse)) {
688 ivpu_err(vdev, "Fuse: invalid (0x%x)\n", fuse);
692 tile_disable = REG_GET_FLD(VPU_40XX_BUTTRESS_TILE_FUSE, CONFIG, fuse);
693 if (!ivpu_tile_disable_check(tile_disable)) {
694 ivpu_err(vdev, "Fuse: Invalid tile disable config (0x%x)\n", tile_disable);
699 ivpu_dbg(vdev, MISC, "Fuse: %d tiles enabled. Tile number %d disabled\n",
700 TILE_MAX_NUM - 1, ffs(tile_disable) - 1);
702 ivpu_dbg(vdev, MISC, "Fuse: All %d tiles enabled\n", TILE_MAX_NUM);
704 tile_enable = (~tile_disable) & TILE_MAX_MASK;
706 hw->sku = REG_SET_FLD_NUM(SKU, HW_ID, LNL_HW_ID, hw->sku);
707 hw->sku = REG_SET_FLD_NUM(SKU, TILE, tile_enable, hw->sku);
708 hw->tile_fuse = tile_disable;
709 hw->pll.profiling_freq = PLL_PROFILING_FREQ_DEFAULT;
711 ivpu_pll_init_frequency_ratios(vdev);
713 ivpu_hw_init_range(&vdev->hw->ranges.global, 0x80000000, SZ_512M);
714 ivpu_hw_init_range(&vdev->hw->ranges.user, 0x80000000, SZ_256M);
715 ivpu_hw_init_range(&vdev->hw->ranges.shave, 0x80000000 + SZ_256M, SZ_2G - SZ_256M);
716 ivpu_hw_init_range(&vdev->hw->ranges.dma, 0x200000000, SZ_8G);
721 static int ivpu_hw_40xx_reset(struct ivpu_device *vdev)
726 ret = REGB_POLL_FLD(VPU_40XX_BUTTRESS_IP_RESET, TRIGGER, 0, TIMEOUT_US);
728 ivpu_err(vdev, "Wait for *_TRIGGER timed out\n");
732 val = REGB_RD32(VPU_40XX_BUTTRESS_IP_RESET);
733 val = REG_SET_FLD(VPU_40XX_BUTTRESS_IP_RESET, TRIGGER, val);
734 REGB_WR32(VPU_40XX_BUTTRESS_IP_RESET, val);
736 ret = REGB_POLL_FLD(VPU_40XX_BUTTRESS_IP_RESET, TRIGGER, 0, TIMEOUT_US);
738 ivpu_err(vdev, "Timed out waiting for RESET completion\n");
743 static int ivpu_hw_40xx_d0i3_enable(struct ivpu_device *vdev)
747 if (IVPU_WA(punit_disabled))
750 ret = ivpu_boot_d0i3_drive(vdev, true);
752 ivpu_err(vdev, "Failed to enable D0i3: %d\n", ret);
754 udelay(5); /* VPU requires 5 us to complete the transition */
759 static int ivpu_hw_40xx_d0i3_disable(struct ivpu_device *vdev)
763 if (IVPU_WA(punit_disabled))
766 ret = ivpu_boot_d0i3_drive(vdev, false);
768 ivpu_err(vdev, "Failed to disable D0i3: %d\n", ret);
773 static void ivpu_hw_40xx_profiling_freq_reg_set(struct ivpu_device *vdev)
775 u32 val = REGB_RD32(VPU_40XX_BUTTRESS_VPU_STATUS);
777 if (vdev->hw->pll.profiling_freq == PLL_PROFILING_FREQ_DEFAULT)
778 val = REG_CLR_FLD(VPU_40XX_BUTTRESS_VPU_STATUS, PERF_CLK, val);
780 val = REG_SET_FLD(VPU_40XX_BUTTRESS_VPU_STATUS, PERF_CLK, val);
782 REGB_WR32(VPU_40XX_BUTTRESS_VPU_STATUS, val);
785 static void ivpu_hw_40xx_ats_print(struct ivpu_device *vdev)
787 ivpu_dbg(vdev, MISC, "Buttress ATS: %s\n",
788 REGB_RD32(VPU_40XX_BUTTRESS_HM_ATS) ? "Enable" : "Disable");
791 static void ivpu_hw_40xx_clock_relinquish_disable(struct ivpu_device *vdev)
793 u32 val = REGB_RD32(VPU_40XX_BUTTRESS_VPU_STATUS);
795 val = REG_SET_FLD(VPU_40XX_BUTTRESS_VPU_STATUS, DISABLE_CLK_RELINQUISH, val);
796 REGB_WR32(VPU_40XX_BUTTRESS_VPU_STATUS, val);
799 static int ivpu_hw_40xx_power_up(struct ivpu_device *vdev)
803 ret = ivpu_hw_40xx_reset(vdev);
805 ivpu_err(vdev, "Failed to reset HW: %d\n", ret);
809 ivpu_hw_read_platform(vdev);
810 ivpu_hw_wa_init(vdev);
811 ivpu_hw_timeouts_init(vdev);
813 ret = ivpu_hw_40xx_d0i3_disable(vdev);
815 ivpu_warn(vdev, "Failed to disable D0I3: %d\n", ret);
817 ret = ivpu_pll_enable(vdev);
819 ivpu_err(vdev, "Failed to enable PLL: %d\n", ret);
823 if (IVPU_WA(disable_clock_relinquish))
824 ivpu_hw_40xx_clock_relinquish_disable(vdev);
825 ivpu_hw_40xx_profiling_freq_reg_set(vdev);
826 ivpu_hw_40xx_ats_print(vdev);
828 ret = ivpu_boot_host_ss_check(vdev);
830 ivpu_err(vdev, "Failed to configure host SS: %d\n", ret);
834 ivpu_boot_idle_gen_drive(vdev, false);
836 ret = ivpu_boot_pwr_domain_enable(vdev);
838 ivpu_err(vdev, "Failed to enable power domain: %d\n", ret);
842 ret = ivpu_boot_host_ss_axi_enable(vdev);
844 ivpu_err(vdev, "Failed to enable AXI: %d\n", ret);
848 ret = ivpu_boot_host_ss_top_noc_enable(vdev);
850 ivpu_err(vdev, "Failed to enable TOP NOC: %d\n", ret);
855 static int ivpu_hw_40xx_boot_fw(struct ivpu_device *vdev)
859 ivpu_boot_no_snoop_enable(vdev);
860 ivpu_boot_tbu_mmu_enable(vdev);
862 ret = ivpu_boot_soc_cpu_boot(vdev);
864 ivpu_err(vdev, "Failed to boot SOC CPU: %d\n", ret);
869 static bool ivpu_hw_40xx_is_idle(struct ivpu_device *vdev)
873 if (IVPU_WA(punit_disabled))
876 val = REGB_RD32(VPU_40XX_BUTTRESS_VPU_STATUS);
877 return REG_TEST_FLD(VPU_40XX_BUTTRESS_VPU_STATUS, READY, val) &&
878 REG_TEST_FLD(VPU_40XX_BUTTRESS_VPU_STATUS, IDLE, val);
881 static int ivpu_hw_40xx_power_down(struct ivpu_device *vdev)
885 if (!ivpu_hw_40xx_is_idle(vdev) && ivpu_hw_40xx_reset(vdev))
886 ivpu_warn(vdev, "Failed to reset the VPU\n");
888 if (ivpu_pll_disable(vdev)) {
889 ivpu_err(vdev, "Failed to disable PLL\n");
893 if (ivpu_hw_40xx_d0i3_enable(vdev)) {
894 ivpu_err(vdev, "Failed to enter D0I3\n");
901 static void ivpu_hw_40xx_wdt_disable(struct ivpu_device *vdev)
905 REGV_WR32(VPU_40XX_CPU_SS_TIM_SAFE, TIM_SAFE_ENABLE);
906 REGV_WR32(VPU_40XX_CPU_SS_TIM_WATCHDOG, TIM_WATCHDOG_RESET_VALUE);
908 REGV_WR32(VPU_40XX_CPU_SS_TIM_SAFE, TIM_SAFE_ENABLE);
909 REGV_WR32(VPU_40XX_CPU_SS_TIM_WDOG_EN, 0);
911 val = REGV_RD32(VPU_40XX_CPU_SS_TIM_GEN_CONFIG);
912 val = REG_CLR_FLD(VPU_40XX_CPU_SS_TIM_GEN_CONFIG, WDOG_TO_INT_CLR, val);
913 REGV_WR32(VPU_40XX_CPU_SS_TIM_GEN_CONFIG, val);
916 /* Register indirect accesses */
917 static u32 ivpu_hw_40xx_reg_pll_freq_get(struct ivpu_device *vdev)
921 pll_curr_ratio = REGB_RD32(VPU_40XX_BUTTRESS_PLL_FREQ);
922 pll_curr_ratio &= VPU_40XX_BUTTRESS_PLL_FREQ_RATIO_MASK;
924 return PLL_RATIO_TO_FREQ(pll_curr_ratio);
927 static u32 ivpu_hw_40xx_reg_telemetry_offset_get(struct ivpu_device *vdev)
929 return REGB_RD32(VPU_40XX_BUTTRESS_VPU_TELEMETRY_OFFSET);
932 static u32 ivpu_hw_40xx_reg_telemetry_size_get(struct ivpu_device *vdev)
934 return REGB_RD32(VPU_40XX_BUTTRESS_VPU_TELEMETRY_SIZE);
937 static u32 ivpu_hw_40xx_reg_telemetry_enable_get(struct ivpu_device *vdev)
939 return REGB_RD32(VPU_40XX_BUTTRESS_VPU_TELEMETRY_ENABLE);
942 static void ivpu_hw_40xx_reg_db_set(struct ivpu_device *vdev, u32 db_id)
944 u32 reg_stride = VPU_40XX_CPU_SS_DOORBELL_1 - VPU_40XX_CPU_SS_DOORBELL_0;
945 u32 val = REG_FLD(VPU_40XX_CPU_SS_DOORBELL_0, SET);
947 REGV_WR32I(VPU_40XX_CPU_SS_DOORBELL_0, reg_stride, db_id, val);
950 static u32 ivpu_hw_40xx_reg_ipc_rx_addr_get(struct ivpu_device *vdev)
952 return REGV_RD32(VPU_40XX_HOST_SS_TIM_IPC_FIFO_ATM);
955 static u32 ivpu_hw_40xx_reg_ipc_rx_count_get(struct ivpu_device *vdev)
957 u32 count = REGV_RD32_SILENT(VPU_40XX_HOST_SS_TIM_IPC_FIFO_STAT);
959 return REG_GET_FLD(VPU_40XX_HOST_SS_TIM_IPC_FIFO_STAT, FILL_LEVEL, count);
962 static void ivpu_hw_40xx_reg_ipc_tx_set(struct ivpu_device *vdev, u32 vpu_addr)
964 REGV_WR32(VPU_40XX_CPU_SS_TIM_IPC_FIFO, vpu_addr);
967 static void ivpu_hw_40xx_irq_clear(struct ivpu_device *vdev)
969 REGV_WR64(VPU_40XX_HOST_SS_ICB_CLEAR_0, ICB_0_1_IRQ_MASK);
972 static void ivpu_hw_40xx_irq_enable(struct ivpu_device *vdev)
974 REGV_WR32(VPU_40XX_HOST_SS_FW_SOC_IRQ_EN, ITF_FIREWALL_VIOLATION_MASK);
975 REGV_WR64(VPU_40XX_HOST_SS_ICB_ENABLE_0, ICB_0_1_IRQ_MASK);
976 REGB_WR32(VPU_40XX_BUTTRESS_LOCAL_INT_MASK, BUTTRESS_IRQ_ENABLE_MASK);
977 REGB_WR32(VPU_40XX_BUTTRESS_GLOBAL_INT_MASK, 0x0);
980 static void ivpu_hw_40xx_irq_disable(struct ivpu_device *vdev)
982 REGB_WR32(VPU_40XX_BUTTRESS_GLOBAL_INT_MASK, 0x1);
983 REGB_WR32(VPU_40XX_BUTTRESS_LOCAL_INT_MASK, BUTTRESS_IRQ_DISABLE_MASK);
984 REGV_WR64(VPU_40XX_HOST_SS_ICB_ENABLE_0, 0x0ull);
985 REGV_WR32(VPU_40XX_HOST_SS_FW_SOC_IRQ_EN, 0x0ul);
988 static void ivpu_hw_40xx_irq_wdt_nce_handler(struct ivpu_device *vdev)
990 /* TODO: For LNN hang consider engine reset instead of full recovery */
991 ivpu_pm_schedule_recovery(vdev);
994 static void ivpu_hw_40xx_irq_wdt_mss_handler(struct ivpu_device *vdev)
996 ivpu_hw_wdt_disable(vdev);
997 ivpu_pm_schedule_recovery(vdev);
1000 static void ivpu_hw_40xx_irq_noc_firewall_handler(struct ivpu_device *vdev)
1002 ivpu_pm_schedule_recovery(vdev);
1005 /* Handler for IRQs from VPU core (irqV) */
1006 static irqreturn_t ivpu_hw_40xx_irqv_handler(struct ivpu_device *vdev, int irq)
1008 u32 status = REGV_RD32(VPU_40XX_HOST_SS_ICB_STATUS_0) & ICB_0_IRQ_MASK;
1009 irqreturn_t ret = IRQ_NONE;
1014 REGV_WR32(VPU_40XX_HOST_SS_ICB_CLEAR_0, status);
1016 if (REG_TEST_FLD(VPU_40XX_HOST_SS_ICB_STATUS_0, MMU_IRQ_0_INT, status))
1017 ivpu_mmu_irq_evtq_handler(vdev);
1019 if (REG_TEST_FLD(VPU_40XX_HOST_SS_ICB_STATUS_0, HOST_IPC_FIFO_INT, status))
1020 ret |= ivpu_ipc_irq_handler(vdev);
1022 if (REG_TEST_FLD(VPU_40XX_HOST_SS_ICB_STATUS_0, MMU_IRQ_1_INT, status))
1023 ivpu_dbg(vdev, IRQ, "MMU sync complete\n");
1025 if (REG_TEST_FLD(VPU_40XX_HOST_SS_ICB_STATUS_0, MMU_IRQ_2_INT, status))
1026 ivpu_mmu_irq_gerr_handler(vdev);
1028 if (REG_TEST_FLD(VPU_40XX_HOST_SS_ICB_STATUS_0, CPU_INT_REDIRECT_0_INT, status))
1029 ivpu_hw_40xx_irq_wdt_mss_handler(vdev);
1031 if (REG_TEST_FLD(VPU_40XX_HOST_SS_ICB_STATUS_0, CPU_INT_REDIRECT_1_INT, status))
1032 ivpu_hw_40xx_irq_wdt_nce_handler(vdev);
1034 if (REG_TEST_FLD(VPU_40XX_HOST_SS_ICB_STATUS_0, NOC_FIREWALL_INT, status))
1035 ivpu_hw_40xx_irq_noc_firewall_handler(vdev);
1040 /* Handler for IRQs from Buttress core (irqB) */
1041 static irqreturn_t ivpu_hw_40xx_irqb_handler(struct ivpu_device *vdev, int irq)
1043 bool schedule_recovery = false;
1044 u32 status = REGB_RD32(VPU_40XX_BUTTRESS_INTERRUPT_STAT) & BUTTRESS_IRQ_MASK;
1049 /* Disable global interrupt before handling local buttress interrupts */
1050 REGB_WR32(VPU_40XX_BUTTRESS_GLOBAL_INT_MASK, 0x1);
1052 if (REG_TEST_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, FREQ_CHANGE, status))
1053 ivpu_dbg(vdev, IRQ, "FREQ_CHANGE");
1055 if (REG_TEST_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, ATS_ERR, status)) {
1056 ivpu_err(vdev, "ATS_ERR LOG1 0x%08x ATS_ERR_LOG2 0x%08x\n",
1057 REGB_RD32(VPU_40XX_BUTTRESS_ATS_ERR_LOG1),
1058 REGB_RD32(VPU_40XX_BUTTRESS_ATS_ERR_LOG2));
1059 REGB_WR32(VPU_40XX_BUTTRESS_ATS_ERR_CLEAR, 0x1);
1060 schedule_recovery = true;
1063 if (REG_TEST_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, CFI0_ERR, status)) {
1064 ivpu_err(vdev, "CFI0_ERR 0x%08x", REGB_RD32(VPU_40XX_BUTTRESS_CFI0_ERR_LOG));
1065 REGB_WR32(VPU_40XX_BUTTRESS_CFI0_ERR_CLEAR, 0x1);
1066 schedule_recovery = true;
1069 if (REG_TEST_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, CFI1_ERR, status)) {
1070 ivpu_err(vdev, "CFI1_ERR 0x%08x", REGB_RD32(VPU_40XX_BUTTRESS_CFI1_ERR_LOG));
1071 REGB_WR32(VPU_40XX_BUTTRESS_CFI1_ERR_CLEAR, 0x1);
1072 schedule_recovery = true;
1075 if (REG_TEST_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, IMR0_ERR, status)) {
1076 ivpu_err(vdev, "IMR_ERR_CFI0 LOW: 0x%08x HIGH: 0x%08x",
1077 REGB_RD32(VPU_40XX_BUTTRESS_IMR_ERR_CFI0_LOW),
1078 REGB_RD32(VPU_40XX_BUTTRESS_IMR_ERR_CFI0_HIGH));
1079 REGB_WR32(VPU_40XX_BUTTRESS_IMR_ERR_CFI0_CLEAR, 0x1);
1080 schedule_recovery = true;
1083 if (REG_TEST_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, IMR1_ERR, status)) {
1084 ivpu_err(vdev, "IMR_ERR_CFI1 LOW: 0x%08x HIGH: 0x%08x",
1085 REGB_RD32(VPU_40XX_BUTTRESS_IMR_ERR_CFI1_LOW),
1086 REGB_RD32(VPU_40XX_BUTTRESS_IMR_ERR_CFI1_HIGH));
1087 REGB_WR32(VPU_40XX_BUTTRESS_IMR_ERR_CFI1_CLEAR, 0x1);
1088 schedule_recovery = true;
1091 if (REG_TEST_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, SURV_ERR, status)) {
1092 ivpu_err(vdev, "Survivability error detected\n");
1093 schedule_recovery = true;
1096 /* This must be done after interrupts are cleared at the source. */
1097 REGB_WR32(VPU_40XX_BUTTRESS_INTERRUPT_STAT, status);
1099 /* Re-enable global interrupt */
1100 REGB_WR32(VPU_40XX_BUTTRESS_GLOBAL_INT_MASK, 0x0);
1102 if (schedule_recovery)
1103 ivpu_pm_schedule_recovery(vdev);
1108 static irqreturn_t ivpu_hw_40xx_irq_handler(int irq, void *ptr)
1110 struct ivpu_device *vdev = ptr;
1111 irqreturn_t ret = IRQ_NONE;
1113 ret |= ivpu_hw_40xx_irqv_handler(vdev, irq);
1114 ret |= ivpu_hw_40xx_irqb_handler(vdev, irq);
1116 if (ret & IRQ_WAKE_THREAD)
1117 return IRQ_WAKE_THREAD;
1122 static void ivpu_hw_40xx_diagnose_failure(struct ivpu_device *vdev)
1124 u32 irqv = REGV_RD32(VPU_40XX_HOST_SS_ICB_STATUS_0) & ICB_0_IRQ_MASK;
1125 u32 irqb = REGB_RD32(VPU_40XX_BUTTRESS_INTERRUPT_STAT) & BUTTRESS_IRQ_MASK;
1127 if (ivpu_hw_40xx_reg_ipc_rx_count_get(vdev))
1128 ivpu_err(vdev, "IPC FIFO queue not empty, missed IPC IRQ");
1130 if (REG_TEST_FLD(VPU_40XX_HOST_SS_ICB_STATUS_0, CPU_INT_REDIRECT_0_INT, irqv))
1131 ivpu_err(vdev, "WDT MSS timeout detected\n");
1133 if (REG_TEST_FLD(VPU_40XX_HOST_SS_ICB_STATUS_0, CPU_INT_REDIRECT_1_INT, irqv))
1134 ivpu_err(vdev, "WDT NCE timeout detected\n");
1136 if (REG_TEST_FLD(VPU_40XX_HOST_SS_ICB_STATUS_0, NOC_FIREWALL_INT, irqv))
1137 ivpu_err(vdev, "NOC Firewall irq detected\n");
1139 if (REG_TEST_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, ATS_ERR, irqb)) {
1140 ivpu_err(vdev, "ATS_ERR_LOG1 0x%08x ATS_ERR_LOG2 0x%08x\n",
1141 REGB_RD32(VPU_40XX_BUTTRESS_ATS_ERR_LOG1),
1142 REGB_RD32(VPU_40XX_BUTTRESS_ATS_ERR_LOG2));
1145 if (REG_TEST_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, CFI0_ERR, irqb))
1146 ivpu_err(vdev, "CFI0_ERR_LOG 0x%08x\n", REGB_RD32(VPU_40XX_BUTTRESS_CFI0_ERR_LOG));
1148 if (REG_TEST_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, CFI1_ERR, irqb))
1149 ivpu_err(vdev, "CFI1_ERR_LOG 0x%08x\n", REGB_RD32(VPU_40XX_BUTTRESS_CFI1_ERR_LOG));
1151 if (REG_TEST_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, IMR0_ERR, irqb))
1152 ivpu_err(vdev, "IMR_ERR_CFI0 LOW: 0x%08x HIGH: 0x%08x\n",
1153 REGB_RD32(VPU_40XX_BUTTRESS_IMR_ERR_CFI0_LOW),
1154 REGB_RD32(VPU_40XX_BUTTRESS_IMR_ERR_CFI0_HIGH));
1156 if (REG_TEST_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, IMR1_ERR, irqb))
1157 ivpu_err(vdev, "IMR_ERR_CFI1 LOW: 0x%08x HIGH: 0x%08x\n",
1158 REGB_RD32(VPU_40XX_BUTTRESS_IMR_ERR_CFI1_LOW),
1159 REGB_RD32(VPU_40XX_BUTTRESS_IMR_ERR_CFI1_HIGH));
1161 if (REG_TEST_FLD(VPU_40XX_BUTTRESS_INTERRUPT_STAT, SURV_ERR, irqb))
1162 ivpu_err(vdev, "Survivability error detected\n");
1165 const struct ivpu_hw_ops ivpu_hw_40xx_ops = {
1166 .info_init = ivpu_hw_40xx_info_init,
1167 .power_up = ivpu_hw_40xx_power_up,
1168 .is_idle = ivpu_hw_40xx_is_idle,
1169 .power_down = ivpu_hw_40xx_power_down,
1170 .boot_fw = ivpu_hw_40xx_boot_fw,
1171 .wdt_disable = ivpu_hw_40xx_wdt_disable,
1172 .diagnose_failure = ivpu_hw_40xx_diagnose_failure,
1173 .reg_pll_freq_get = ivpu_hw_40xx_reg_pll_freq_get,
1174 .reg_telemetry_offset_get = ivpu_hw_40xx_reg_telemetry_offset_get,
1175 .reg_telemetry_size_get = ivpu_hw_40xx_reg_telemetry_size_get,
1176 .reg_telemetry_enable_get = ivpu_hw_40xx_reg_telemetry_enable_get,
1177 .reg_db_set = ivpu_hw_40xx_reg_db_set,
1178 .reg_ipc_rx_addr_get = ivpu_hw_40xx_reg_ipc_rx_addr_get,
1179 .reg_ipc_rx_count_get = ivpu_hw_40xx_reg_ipc_rx_count_get,
1180 .reg_ipc_tx_set = ivpu_hw_40xx_reg_ipc_tx_set,
1181 .irq_clear = ivpu_hw_40xx_irq_clear,
1182 .irq_enable = ivpu_hw_40xx_irq_enable,
1183 .irq_disable = ivpu_hw_40xx_irq_disable,
1184 .irq_handler = ivpu_hw_40xx_irq_handler,