2 * Copyright 2020 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
24 #include <linux/pci.h>
27 #include "amdgpu_ih.h"
30 #include "oss/osssys_4_2_0_offset.h"
31 #include "oss/osssys_4_2_0_sh_mask.h"
33 #include "soc15_common.h"
34 #include "vega20_ih.h"
36 #define MAX_REARM_RETRY 10
38 #define mmIH_CHICKEN_ALDEBARAN 0x18d
39 #define mmIH_CHICKEN_ALDEBARAN_BASE_IDX 0
41 #define mmIH_RETRY_INT_CAM_CNTL_ALDEBARAN 0x00ea
42 #define mmIH_RETRY_INT_CAM_CNTL_ALDEBARAN_BASE_IDX 0
43 #define IH_RETRY_INT_CAM_CNTL_ALDEBARAN__ENABLE__SHIFT 0x10
44 #define IH_RETRY_INT_CAM_CNTL_ALDEBARAN__ENABLE_MASK 0x00010000L
46 static void vega20_ih_set_interrupt_funcs(struct amdgpu_device *adev);
49 * vega20_ih_init_register_offset - Initialize register offset for ih rings
51 * @adev: amdgpu_device pointer
53 * Initialize register offset ih rings (VEGA20).
55 static void vega20_ih_init_register_offset(struct amdgpu_device *adev)
57 struct amdgpu_ih_regs *ih_regs;
59 if (adev->irq.ih.ring_size) {
60 ih_regs = &adev->irq.ih.ih_regs;
61 ih_regs->ih_rb_base = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_RB_BASE);
62 ih_regs->ih_rb_base_hi = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_RB_BASE_HI);
63 ih_regs->ih_rb_cntl = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_RB_CNTL);
64 ih_regs->ih_rb_wptr = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_RB_WPTR);
65 ih_regs->ih_rb_rptr = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_RB_RPTR);
66 ih_regs->ih_doorbell_rptr = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_DOORBELL_RPTR);
67 ih_regs->ih_rb_wptr_addr_lo = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_RB_WPTR_ADDR_LO);
68 ih_regs->ih_rb_wptr_addr_hi = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_RB_WPTR_ADDR_HI);
69 ih_regs->psp_reg_id = PSP_REG_IH_RB_CNTL;
72 if (adev->irq.ih1.ring_size) {
73 ih_regs = &adev->irq.ih1.ih_regs;
74 ih_regs->ih_rb_base = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_RB_BASE_RING1);
75 ih_regs->ih_rb_base_hi = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_RB_BASE_HI_RING1);
76 ih_regs->ih_rb_cntl = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_RB_CNTL_RING1);
77 ih_regs->ih_rb_wptr = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_RB_WPTR_RING1);
78 ih_regs->ih_rb_rptr = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_RB_RPTR_RING1);
79 ih_regs->ih_doorbell_rptr = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_DOORBELL_RPTR_RING1);
80 ih_regs->psp_reg_id = PSP_REG_IH_RB_CNTL_RING1;
83 if (adev->irq.ih2.ring_size) {
84 ih_regs = &adev->irq.ih2.ih_regs;
85 ih_regs->ih_rb_base = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_RB_BASE_RING2);
86 ih_regs->ih_rb_base_hi = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_RB_BASE_HI_RING2);
87 ih_regs->ih_rb_cntl = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_RB_CNTL_RING2);
88 ih_regs->ih_rb_wptr = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_RB_WPTR_RING2);
89 ih_regs->ih_rb_rptr = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_RB_RPTR_RING2);
90 ih_regs->ih_doorbell_rptr = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_DOORBELL_RPTR_RING2);
91 ih_regs->psp_reg_id = PSP_REG_IH_RB_CNTL_RING2;
96 * vega20_ih_toggle_ring_interrupts - toggle the interrupt ring buffer
98 * @adev: amdgpu_device pointer
99 * @ih: amdgpu_ih_ring pointer
100 * @enable: true - enable the interrupts, false - disable the interrupts
102 * Toggle the interrupt ring buffer (VEGA20)
104 static int vega20_ih_toggle_ring_interrupts(struct amdgpu_device *adev,
105 struct amdgpu_ih_ring *ih,
108 struct amdgpu_ih_regs *ih_regs;
111 ih_regs = &ih->ih_regs;
113 tmp = RREG32(ih_regs->ih_rb_cntl);
114 tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, RB_ENABLE, (enable ? 1 : 0));
115 tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, RB_GPU_TS_ENABLE, 1);
117 /* enable_intr field is only valid in ring0 */
118 if (ih == &adev->irq.ih)
119 tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, ENABLE_INTR, (enable ? 1 : 0));
120 if (amdgpu_sriov_vf(adev)) {
121 if (psp_reg_program(&adev->psp, ih_regs->psp_reg_id, tmp)) {
122 dev_err(adev->dev, "PSP program IH_RB_CNTL failed!\n");
126 WREG32(ih_regs->ih_rb_cntl, tmp);
132 /* set rptr, wptr to 0 */
133 WREG32(ih_regs->ih_rb_rptr, 0);
134 WREG32(ih_regs->ih_rb_wptr, 0);
143 * vega20_ih_toggle_interrupts - Toggle all the available interrupt ring buffers
145 * @adev: amdgpu_device pointer
146 * @enable: enable or disable interrupt ring buffers
148 * Toggle all the available interrupt ring buffers (VEGA20).
150 static int vega20_ih_toggle_interrupts(struct amdgpu_device *adev, bool enable)
152 struct amdgpu_ih_ring *ih[] = {&adev->irq.ih, &adev->irq.ih1, &adev->irq.ih2};
156 for (i = 0; i < ARRAY_SIZE(ih); i++) {
157 if (ih[i]->ring_size) {
158 r = vega20_ih_toggle_ring_interrupts(adev, ih[i], enable);
167 static uint32_t vega20_ih_rb_cntl(struct amdgpu_ih_ring *ih, uint32_t ih_rb_cntl)
169 int rb_bufsz = order_base_2(ih->ring_size / 4);
171 ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL,
172 MC_SPACE, ih->use_bus_addr ? 1 : 4);
173 ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL,
174 WPTR_OVERFLOW_CLEAR, 1);
175 ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL,
176 WPTR_OVERFLOW_ENABLE, 1);
177 ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, RB_SIZE, rb_bufsz);
178 /* Ring Buffer write pointer writeback. If enabled, IH_RB_WPTR register
179 * value is written to memory
181 ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL,
182 WPTR_WRITEBACK_ENABLE, 1);
183 ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, MC_SNOOP, 1);
184 ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, MC_RO, 0);
185 ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, MC_VMID, 0);
190 static uint32_t vega20_ih_doorbell_rptr(struct amdgpu_ih_ring *ih)
192 u32 ih_doorbell_rtpr = 0;
194 if (ih->use_doorbell) {
195 ih_doorbell_rtpr = REG_SET_FIELD(ih_doorbell_rtpr,
196 IH_DOORBELL_RPTR, OFFSET,
198 ih_doorbell_rtpr = REG_SET_FIELD(ih_doorbell_rtpr,
202 ih_doorbell_rtpr = REG_SET_FIELD(ih_doorbell_rtpr,
206 return ih_doorbell_rtpr;
210 * vega20_ih_enable_ring - enable an ih ring buffer
212 * @adev: amdgpu_device pointer
213 * @ih: amdgpu_ih_ring pointer
215 * Enable an ih ring buffer (VEGA20)
217 static int vega20_ih_enable_ring(struct amdgpu_device *adev,
218 struct amdgpu_ih_ring *ih)
220 struct amdgpu_ih_regs *ih_regs;
223 ih_regs = &ih->ih_regs;
225 /* Ring Buffer base. [39:8] of 40-bit address of the beginning of the ring buffer*/
226 WREG32(ih_regs->ih_rb_base, ih->gpu_addr >> 8);
227 WREG32(ih_regs->ih_rb_base_hi, (ih->gpu_addr >> 40) & 0xff);
229 tmp = RREG32(ih_regs->ih_rb_cntl);
230 tmp = vega20_ih_rb_cntl(ih, tmp);
231 if (ih == &adev->irq.ih)
232 tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, RPTR_REARM, !!adev->irq.msi_enabled);
233 if (ih == &adev->irq.ih1)
234 tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, RB_FULL_DRAIN_ENABLE, 1);
235 if (amdgpu_sriov_vf(adev)) {
236 if (psp_reg_program(&adev->psp, ih_regs->psp_reg_id, tmp)) {
237 dev_err(adev->dev, "PSP program IH_RB_CNTL failed!\n");
241 WREG32(ih_regs->ih_rb_cntl, tmp);
244 if (ih == &adev->irq.ih) {
245 /* set the ih ring 0 writeback address whether it's enabled or not */
246 WREG32(ih_regs->ih_rb_wptr_addr_lo, lower_32_bits(ih->wptr_addr));
247 WREG32(ih_regs->ih_rb_wptr_addr_hi, upper_32_bits(ih->wptr_addr) & 0xFFFF);
250 /* set rptr, wptr to 0 */
251 WREG32(ih_regs->ih_rb_wptr, 0);
252 WREG32(ih_regs->ih_rb_rptr, 0);
254 WREG32(ih_regs->ih_doorbell_rptr, vega20_ih_doorbell_rptr(ih));
259 static uint32_t vega20_setup_retry_doorbell(u32 doorbell_index)
263 val = REG_SET_FIELD(val, IH_DOORBELL_RPTR, OFFSET, doorbell_index);
264 val = REG_SET_FIELD(val, IH_DOORBELL_RPTR, ENABLE, 1);
270 * vega20_ih_irq_init - init and enable the interrupt ring
272 * @adev: amdgpu_device pointer
274 * Allocate a ring buffer for the interrupt controller,
275 * enable the RLC, disable interrupts, enable the IH
276 * ring buffer and enable it (VI).
277 * Called at device load and reume.
278 * Returns 0 for success, errors for failure.
280 static int vega20_ih_irq_init(struct amdgpu_device *adev)
282 struct amdgpu_ih_ring *ih[] = {&adev->irq.ih, &adev->irq.ih1, &adev->irq.ih2};
288 ret = vega20_ih_toggle_interrupts(adev, false);
292 adev->nbio.funcs->ih_control(adev);
294 if (!amdgpu_sriov_vf(adev)) {
295 if ((amdgpu_ip_version(adev, OSSSYS_HWIP, 0) == IP_VERSION(4, 2, 1)) &&
296 adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT) {
297 ih_chicken = RREG32_SOC15(OSSSYS, 0, mmIH_CHICKEN);
298 if (adev->irq.ih.use_bus_addr) {
299 ih_chicken = REG_SET_FIELD(ih_chicken, IH_CHICKEN,
300 MC_SPACE_GPA_ENABLE, 1);
302 WREG32_SOC15(OSSSYS, 0, mmIH_CHICKEN, ih_chicken);
305 /* psp firmware won't program IH_CHICKEN for aldebaran
306 * driver needs to program it properly according to
307 * MC_SPACE type in IH_RB_CNTL */
308 if ((amdgpu_ip_version(adev, OSSSYS_HWIP, 0) == IP_VERSION(4, 4, 0)) ||
309 (amdgpu_ip_version(adev, OSSSYS_HWIP, 0) == IP_VERSION(4, 4, 2)) ||
310 (amdgpu_ip_version(adev, OSSSYS_HWIP, 0) == IP_VERSION(4, 4, 5))) {
311 ih_chicken = RREG32_SOC15(OSSSYS, 0, mmIH_CHICKEN_ALDEBARAN);
312 if (adev->irq.ih.use_bus_addr) {
313 ih_chicken = REG_SET_FIELD(ih_chicken, IH_CHICKEN,
314 MC_SPACE_GPA_ENABLE, 1);
316 WREG32_SOC15(OSSSYS, 0, mmIH_CHICKEN_ALDEBARAN, ih_chicken);
320 for (i = 0; i < ARRAY_SIZE(ih); i++) {
321 if (ih[i]->ring_size) {
322 ret = vega20_ih_enable_ring(adev, ih[i]);
328 if (!amdgpu_sriov_vf(adev))
329 adev->nbio.funcs->ih_doorbell_range(adev, adev->irq.ih.use_doorbell,
330 adev->irq.ih.doorbell_index);
332 pci_set_master(adev->pdev);
334 /* Allocate the doorbell for IH Retry CAM */
335 adev->irq.retry_cam_doorbell_index = (adev->doorbell_index.ih + 3) << 1;
336 WREG32_SOC15(OSSSYS, 0, mmIH_DOORBELL_RETRY_CAM,
337 vega20_setup_retry_doorbell(adev->irq.retry_cam_doorbell_index));
339 /* Enable IH Retry CAM */
340 if (amdgpu_ip_version(adev, OSSSYS_HWIP, 0) == IP_VERSION(4, 4, 0) ||
341 amdgpu_ip_version(adev, OSSSYS_HWIP, 0) == IP_VERSION(4, 4, 2) ||
342 amdgpu_ip_version(adev, OSSSYS_HWIP, 0) == IP_VERSION(4, 4, 5))
343 WREG32_FIELD15(OSSSYS, 0, IH_RETRY_INT_CAM_CNTL_ALDEBARAN,
346 WREG32_FIELD15(OSSSYS, 0, IH_RETRY_INT_CAM_CNTL, ENABLE, 1);
348 adev->irq.retry_cam_enabled = true;
350 /* enable interrupts */
351 ret = vega20_ih_toggle_interrupts(adev, true);
355 if (adev->irq.ih_soft.ring_size)
356 adev->irq.ih_soft.enabled = true;
362 * vega20_ih_irq_disable - disable interrupts
364 * @adev: amdgpu_device pointer
366 * Disable interrupts on the hw (VEGA20).
368 static void vega20_ih_irq_disable(struct amdgpu_device *adev)
370 vega20_ih_toggle_interrupts(adev, false);
372 /* Wait and acknowledge irq */
377 * vega20_ih_get_wptr - get the IH ring buffer wptr
379 * @adev: amdgpu_device pointer
380 * @ih: amdgpu_ih_ring pointer
382 * Get the IH ring buffer wptr from either the register
383 * or the writeback memory buffer (VEGA20). Also check for
384 * ring buffer overflow and deal with it.
385 * Returns the value of the wptr.
387 static u32 vega20_ih_get_wptr(struct amdgpu_device *adev,
388 struct amdgpu_ih_ring *ih)
391 struct amdgpu_ih_regs *ih_regs;
393 if (ih == &adev->irq.ih || ih == &adev->irq.ih_soft) {
394 /* Only ring0 supports writeback. On other rings fall back
395 * to register-based code with overflow checking below.
396 * ih_soft ring doesn't have any backing hardware registers,
397 * update wptr and return.
399 wptr = le32_to_cpu(*ih->wptr_cpu);
401 if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
405 ih_regs = &ih->ih_regs;
407 /* Double check that the overflow wasn't already cleared. */
408 wptr = RREG32_NO_KIQ(ih_regs->ih_rb_wptr);
409 if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
412 wptr = REG_SET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW, 0);
414 /* When a ring buffer overflow happen start parsing interrupt
415 * from the last not overwritten vector (wptr + 32). Hopefully
416 * this should allow us to catchup.
418 tmp = (wptr + 32) & ih->ptr_mask;
419 dev_warn(adev->dev, "IH ring buffer overflow "
420 "(0x%08X, 0x%08X, 0x%08X)\n",
421 wptr, ih->rptr, tmp);
424 tmp = RREG32_NO_KIQ(ih_regs->ih_rb_cntl);
425 tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, WPTR_OVERFLOW_CLEAR, 1);
426 WREG32_NO_KIQ(ih_regs->ih_rb_cntl, tmp);
428 /* Unset the CLEAR_OVERFLOW bit immediately so new overflows
431 tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, WPTR_OVERFLOW_CLEAR, 0);
432 WREG32_NO_KIQ(ih_regs->ih_rb_cntl, tmp);
435 return (wptr & ih->ptr_mask);
439 * vega20_ih_irq_rearm - rearm IRQ if lost
441 * @adev: amdgpu_device pointer
442 * @ih: amdgpu_ih_ring pointer
445 static void vega20_ih_irq_rearm(struct amdgpu_device *adev,
446 struct amdgpu_ih_ring *ih)
450 struct amdgpu_ih_regs *ih_regs;
452 ih_regs = &ih->ih_regs;
454 /* Rearm IRQ / re-wwrite doorbell if doorbell write is lost */
455 for (i = 0; i < MAX_REARM_RETRY; i++) {
456 v = RREG32_NO_KIQ(ih_regs->ih_rb_rptr);
457 if ((v < ih->ring_size) && (v != ih->rptr))
458 WDOORBELL32(ih->doorbell_index, ih->rptr);
465 * vega20_ih_set_rptr - set the IH ring buffer rptr
467 * @adev: amdgpu_device pointer
468 * @ih: amdgpu_ih_ring pointer
470 * Set the IH ring buffer rptr.
472 static void vega20_ih_set_rptr(struct amdgpu_device *adev,
473 struct amdgpu_ih_ring *ih)
475 struct amdgpu_ih_regs *ih_regs;
477 if (ih == &adev->irq.ih_soft)
480 if (ih->use_doorbell) {
481 /* XXX check if swapping is necessary on BE */
482 *ih->rptr_cpu = ih->rptr;
483 WDOORBELL32(ih->doorbell_index, ih->rptr);
485 if (amdgpu_sriov_vf(adev))
486 vega20_ih_irq_rearm(adev, ih);
488 ih_regs = &ih->ih_regs;
489 WREG32(ih_regs->ih_rb_rptr, ih->rptr);
494 * vega20_ih_self_irq - dispatch work for ring 1 and 2
496 * @adev: amdgpu_device pointer
497 * @source: irq source
498 * @entry: IV with WPTR update
500 * Update the WPTR from the IV and schedule work to handle the entries.
502 static int vega20_ih_self_irq(struct amdgpu_device *adev,
503 struct amdgpu_irq_src *source,
504 struct amdgpu_iv_entry *entry)
506 switch (entry->ring_id) {
508 schedule_work(&adev->irq.ih1_work);
511 schedule_work(&adev->irq.ih2_work);
519 static const struct amdgpu_irq_src_funcs vega20_ih_self_irq_funcs = {
520 .process = vega20_ih_self_irq,
523 static void vega20_ih_set_self_irq_funcs(struct amdgpu_device *adev)
525 adev->irq.self_irq.num_types = 0;
526 adev->irq.self_irq.funcs = &vega20_ih_self_irq_funcs;
529 static int vega20_ih_early_init(void *handle)
531 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
533 vega20_ih_set_interrupt_funcs(adev);
534 vega20_ih_set_self_irq_funcs(adev);
538 static int vega20_ih_sw_init(void *handle)
540 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
541 bool use_bus_addr = true;
544 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_IH, 0,
545 &adev->irq.self_irq);
549 if ((adev->flags & AMD_IS_APU) &&
550 (amdgpu_ip_version(adev, OSSSYS_HWIP, 0) == IP_VERSION(4, 4, 2)))
551 use_bus_addr = false;
553 r = amdgpu_ih_ring_init(adev, &adev->irq.ih, IH_RING_SIZE, use_bus_addr);
557 adev->irq.ih.use_doorbell = true;
558 adev->irq.ih.doorbell_index = adev->doorbell_index.ih << 1;
560 r = amdgpu_ih_ring_init(adev, &adev->irq.ih1, PAGE_SIZE, use_bus_addr);
564 adev->irq.ih1.use_doorbell = true;
565 adev->irq.ih1.doorbell_index = (adev->doorbell_index.ih + 1) << 1;
567 if (amdgpu_ip_version(adev, OSSSYS_HWIP, 0) != IP_VERSION(4, 4, 2) &&
568 amdgpu_ip_version(adev, OSSSYS_HWIP, 0) != IP_VERSION(4, 4, 5)) {
569 r = amdgpu_ih_ring_init(adev, &adev->irq.ih2, PAGE_SIZE, true);
573 adev->irq.ih2.use_doorbell = true;
574 adev->irq.ih2.doorbell_index = (adev->doorbell_index.ih + 2) << 1;
577 /* initialize ih control registers offset */
578 vega20_ih_init_register_offset(adev);
580 r = amdgpu_ih_ring_init(adev, &adev->irq.ih_soft, IH_SW_RING_SIZE, use_bus_addr);
584 r = amdgpu_irq_init(adev);
589 static int vega20_ih_sw_fini(void *handle)
591 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
593 amdgpu_irq_fini_sw(adev);
598 static int vega20_ih_hw_init(void *handle)
601 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
603 r = vega20_ih_irq_init(adev);
610 static int vega20_ih_hw_fini(void *handle)
612 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
614 vega20_ih_irq_disable(adev);
619 static int vega20_ih_suspend(void *handle)
621 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
623 return vega20_ih_hw_fini(adev);
626 static int vega20_ih_resume(void *handle)
628 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
630 return vega20_ih_hw_init(adev);
633 static bool vega20_ih_is_idle(void *handle)
639 static int vega20_ih_wait_for_idle(void *handle)
645 static int vega20_ih_soft_reset(void *handle)
652 static void vega20_ih_update_clockgating_state(struct amdgpu_device *adev,
655 uint32_t data, def, field_val;
657 if (adev->cg_flags & AMD_CG_SUPPORT_IH_CG) {
658 def = data = RREG32_SOC15(OSSSYS, 0, mmIH_CLK_CTRL);
659 field_val = enable ? 0 : 1;
660 data = REG_SET_FIELD(data, IH_CLK_CTRL,
661 IH_RETRY_INT_CAM_MEM_CLK_SOFT_OVERRIDE, field_val);
662 data = REG_SET_FIELD(data, IH_CLK_CTRL,
663 IH_BUFFER_MEM_CLK_SOFT_OVERRIDE, field_val);
664 data = REG_SET_FIELD(data, IH_CLK_CTRL,
665 DBUS_MUX_CLK_SOFT_OVERRIDE, field_val);
666 data = REG_SET_FIELD(data, IH_CLK_CTRL,
667 OSSSYS_SHARE_CLK_SOFT_OVERRIDE, field_val);
668 data = REG_SET_FIELD(data, IH_CLK_CTRL,
669 LIMIT_SMN_CLK_SOFT_OVERRIDE, field_val);
670 data = REG_SET_FIELD(data, IH_CLK_CTRL,
671 DYN_CLK_SOFT_OVERRIDE, field_val);
672 data = REG_SET_FIELD(data, IH_CLK_CTRL,
673 REG_CLK_SOFT_OVERRIDE, field_val);
675 WREG32_SOC15(OSSSYS, 0, mmIH_CLK_CTRL, data);
679 static int vega20_ih_set_clockgating_state(void *handle,
680 enum amd_clockgating_state state)
682 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
684 vega20_ih_update_clockgating_state(adev,
685 state == AMD_CG_STATE_GATE);
690 static int vega20_ih_set_powergating_state(void *handle,
691 enum amd_powergating_state state)
696 const struct amd_ip_funcs vega20_ih_ip_funcs = {
698 .early_init = vega20_ih_early_init,
700 .sw_init = vega20_ih_sw_init,
701 .sw_fini = vega20_ih_sw_fini,
702 .hw_init = vega20_ih_hw_init,
703 .hw_fini = vega20_ih_hw_fini,
704 .suspend = vega20_ih_suspend,
705 .resume = vega20_ih_resume,
706 .is_idle = vega20_ih_is_idle,
707 .wait_for_idle = vega20_ih_wait_for_idle,
708 .soft_reset = vega20_ih_soft_reset,
709 .set_clockgating_state = vega20_ih_set_clockgating_state,
710 .set_powergating_state = vega20_ih_set_powergating_state,
713 static const struct amdgpu_ih_funcs vega20_ih_funcs = {
714 .get_wptr = vega20_ih_get_wptr,
715 .decode_iv = amdgpu_ih_decode_iv_helper,
716 .decode_iv_ts = amdgpu_ih_decode_iv_ts_helper,
717 .set_rptr = vega20_ih_set_rptr
720 static void vega20_ih_set_interrupt_funcs(struct amdgpu_device *adev)
722 adev->irq.ih_funcs = &vega20_ih_funcs;
725 const struct amdgpu_ip_block_version vega20_ih_ip_block = {
726 .type = AMD_IP_BLOCK_TYPE_IH,
730 .funcs = &vega20_ih_ip_funcs,