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);
118 /* Unset the CLEAR_OVERFLOW bit to make sure the next step
119 * is switching the bit from 0 to 1
121 tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, WPTR_OVERFLOW_CLEAR, 0);
122 if (amdgpu_sriov_vf(adev) && amdgpu_sriov_reg_indirect_ih(adev)) {
123 if (psp_reg_program(&adev->psp, ih_regs->psp_reg_id, tmp))
126 WREG32_NO_KIQ(ih_regs->ih_rb_cntl, tmp);
129 /* Clear RB_OVERFLOW bit */
130 tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, WPTR_OVERFLOW_CLEAR, 1);
131 if (amdgpu_sriov_vf(adev) && amdgpu_sriov_reg_indirect_ih(adev)) {
132 if (psp_reg_program(&adev->psp, ih_regs->psp_reg_id, tmp))
135 WREG32_NO_KIQ(ih_regs->ih_rb_cntl, tmp);
138 /* Unset the CLEAR_OVERFLOW bit immediately so new overflows
141 tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, WPTR_OVERFLOW_CLEAR, 0);
144 /* enable_intr field is only valid in ring0 */
145 if (ih == &adev->irq.ih)
146 tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, ENABLE_INTR, (enable ? 1 : 0));
147 if (amdgpu_sriov_vf(adev)) {
148 if (psp_reg_program(&adev->psp, ih_regs->psp_reg_id, tmp)) {
149 dev_err(adev->dev, "PSP program IH_RB_CNTL failed!\n");
153 WREG32(ih_regs->ih_rb_cntl, tmp);
159 /* set rptr, wptr to 0 */
160 WREG32(ih_regs->ih_rb_rptr, 0);
161 WREG32(ih_regs->ih_rb_wptr, 0);
170 * vega20_ih_toggle_interrupts - Toggle all the available interrupt ring buffers
172 * @adev: amdgpu_device pointer
173 * @enable: enable or disable interrupt ring buffers
175 * Toggle all the available interrupt ring buffers (VEGA20).
177 static int vega20_ih_toggle_interrupts(struct amdgpu_device *adev, bool enable)
179 struct amdgpu_ih_ring *ih[] = {&adev->irq.ih, &adev->irq.ih1, &adev->irq.ih2};
183 for (i = 0; i < ARRAY_SIZE(ih); i++) {
184 if (ih[i]->ring_size) {
185 r = vega20_ih_toggle_ring_interrupts(adev, ih[i], enable);
194 static uint32_t vega20_ih_rb_cntl(struct amdgpu_ih_ring *ih, uint32_t ih_rb_cntl)
196 int rb_bufsz = order_base_2(ih->ring_size / 4);
198 ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL,
199 MC_SPACE, ih->use_bus_addr ? 1 : 4);
200 ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL,
201 WPTR_OVERFLOW_CLEAR, 1);
202 ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL,
203 WPTR_OVERFLOW_ENABLE, 1);
204 ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, RB_SIZE, rb_bufsz);
205 /* Ring Buffer write pointer writeback. If enabled, IH_RB_WPTR register
206 * value is written to memory
208 ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL,
209 WPTR_WRITEBACK_ENABLE, 1);
210 ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, MC_SNOOP, 1);
211 ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, MC_RO, 0);
212 ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, MC_VMID, 0);
217 static uint32_t vega20_ih_doorbell_rptr(struct amdgpu_ih_ring *ih)
219 u32 ih_doorbell_rtpr = 0;
221 if (ih->use_doorbell) {
222 ih_doorbell_rtpr = REG_SET_FIELD(ih_doorbell_rtpr,
223 IH_DOORBELL_RPTR, OFFSET,
225 ih_doorbell_rtpr = REG_SET_FIELD(ih_doorbell_rtpr,
229 ih_doorbell_rtpr = REG_SET_FIELD(ih_doorbell_rtpr,
233 return ih_doorbell_rtpr;
237 * vega20_ih_enable_ring - enable an ih ring buffer
239 * @adev: amdgpu_device pointer
240 * @ih: amdgpu_ih_ring pointer
242 * Enable an ih ring buffer (VEGA20)
244 static int vega20_ih_enable_ring(struct amdgpu_device *adev,
245 struct amdgpu_ih_ring *ih)
247 struct amdgpu_ih_regs *ih_regs;
250 ih_regs = &ih->ih_regs;
252 /* Ring Buffer base. [39:8] of 40-bit address of the beginning of the ring buffer*/
253 WREG32(ih_regs->ih_rb_base, ih->gpu_addr >> 8);
254 WREG32(ih_regs->ih_rb_base_hi, (ih->gpu_addr >> 40) & 0xff);
256 tmp = RREG32(ih_regs->ih_rb_cntl);
257 tmp = vega20_ih_rb_cntl(ih, tmp);
258 if (ih == &adev->irq.ih)
259 tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, RPTR_REARM, !!adev->irq.msi_enabled);
260 if (ih == &adev->irq.ih1)
261 tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, RB_FULL_DRAIN_ENABLE, 1);
262 if (amdgpu_sriov_vf(adev)) {
263 if (psp_reg_program(&adev->psp, ih_regs->psp_reg_id, tmp)) {
264 dev_err(adev->dev, "PSP program IH_RB_CNTL failed!\n");
268 WREG32(ih_regs->ih_rb_cntl, tmp);
271 if (ih == &adev->irq.ih) {
272 /* set the ih ring 0 writeback address whether it's enabled or not */
273 WREG32(ih_regs->ih_rb_wptr_addr_lo, lower_32_bits(ih->wptr_addr));
274 WREG32(ih_regs->ih_rb_wptr_addr_hi, upper_32_bits(ih->wptr_addr) & 0xFFFF);
277 /* set rptr, wptr to 0 */
278 WREG32(ih_regs->ih_rb_wptr, 0);
279 WREG32(ih_regs->ih_rb_rptr, 0);
281 WREG32(ih_regs->ih_doorbell_rptr, vega20_ih_doorbell_rptr(ih));
286 static uint32_t vega20_setup_retry_doorbell(u32 doorbell_index)
290 val = REG_SET_FIELD(val, IH_DOORBELL_RPTR, OFFSET, doorbell_index);
291 val = REG_SET_FIELD(val, IH_DOORBELL_RPTR, ENABLE, 1);
297 * vega20_ih_irq_init - init and enable the interrupt ring
299 * @adev: amdgpu_device pointer
301 * Allocate a ring buffer for the interrupt controller,
302 * enable the RLC, disable interrupts, enable the IH
303 * ring buffer and enable it (VI).
304 * Called at device load and reume.
305 * Returns 0 for success, errors for failure.
307 static int vega20_ih_irq_init(struct amdgpu_device *adev)
309 struct amdgpu_ih_ring *ih[] = {&adev->irq.ih, &adev->irq.ih1, &adev->irq.ih2};
315 ret = vega20_ih_toggle_interrupts(adev, false);
319 adev->nbio.funcs->ih_control(adev);
321 if (!amdgpu_sriov_vf(adev)) {
322 if ((amdgpu_ip_version(adev, OSSSYS_HWIP, 0) == IP_VERSION(4, 2, 1)) &&
323 adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT) {
324 ih_chicken = RREG32_SOC15(OSSSYS, 0, mmIH_CHICKEN);
325 if (adev->irq.ih.use_bus_addr) {
326 ih_chicken = REG_SET_FIELD(ih_chicken, IH_CHICKEN,
327 MC_SPACE_GPA_ENABLE, 1);
329 WREG32_SOC15(OSSSYS, 0, mmIH_CHICKEN, ih_chicken);
332 /* psp firmware won't program IH_CHICKEN for aldebaran
333 * driver needs to program it properly according to
334 * MC_SPACE type in IH_RB_CNTL */
335 if ((amdgpu_ip_version(adev, OSSSYS_HWIP, 0) == IP_VERSION(4, 4, 0)) ||
336 (amdgpu_ip_version(adev, OSSSYS_HWIP, 0) == IP_VERSION(4, 4, 2)) ||
337 (amdgpu_ip_version(adev, OSSSYS_HWIP, 0) == IP_VERSION(4, 4, 5))) {
338 ih_chicken = RREG32_SOC15(OSSSYS, 0, mmIH_CHICKEN_ALDEBARAN);
339 if (adev->irq.ih.use_bus_addr) {
340 ih_chicken = REG_SET_FIELD(ih_chicken, IH_CHICKEN,
341 MC_SPACE_GPA_ENABLE, 1);
343 WREG32_SOC15(OSSSYS, 0, mmIH_CHICKEN_ALDEBARAN, ih_chicken);
347 for (i = 0; i < ARRAY_SIZE(ih); i++) {
348 if (ih[i]->ring_size) {
349 ret = vega20_ih_enable_ring(adev, ih[i]);
355 if (!amdgpu_sriov_vf(adev))
356 adev->nbio.funcs->ih_doorbell_range(adev, adev->irq.ih.use_doorbell,
357 adev->irq.ih.doorbell_index);
359 pci_set_master(adev->pdev);
361 /* Allocate the doorbell for IH Retry CAM */
362 adev->irq.retry_cam_doorbell_index = (adev->doorbell_index.ih + 3) << 1;
363 WREG32_SOC15(OSSSYS, 0, mmIH_DOORBELL_RETRY_CAM,
364 vega20_setup_retry_doorbell(adev->irq.retry_cam_doorbell_index));
366 /* Enable IH Retry CAM */
367 if (amdgpu_ip_version(adev, OSSSYS_HWIP, 0) == IP_VERSION(4, 4, 0) ||
368 amdgpu_ip_version(adev, OSSSYS_HWIP, 0) == IP_VERSION(4, 4, 2) ||
369 amdgpu_ip_version(adev, OSSSYS_HWIP, 0) == IP_VERSION(4, 4, 4) ||
370 amdgpu_ip_version(adev, OSSSYS_HWIP, 0) == IP_VERSION(4, 4, 5))
371 WREG32_FIELD15(OSSSYS, 0, IH_RETRY_INT_CAM_CNTL_ALDEBARAN,
374 WREG32_FIELD15(OSSSYS, 0, IH_RETRY_INT_CAM_CNTL, ENABLE, 1);
376 adev->irq.retry_cam_enabled = true;
378 /* enable interrupts */
379 ret = vega20_ih_toggle_interrupts(adev, true);
383 if (adev->irq.ih_soft.ring_size)
384 adev->irq.ih_soft.enabled = true;
390 * vega20_ih_irq_disable - disable interrupts
392 * @adev: amdgpu_device pointer
394 * Disable interrupts on the hw (VEGA20).
396 static void vega20_ih_irq_disable(struct amdgpu_device *adev)
398 vega20_ih_toggle_interrupts(adev, false);
400 /* Wait and acknowledge irq */
405 * vega20_ih_get_wptr - get the IH ring buffer wptr
407 * @adev: amdgpu_device pointer
408 * @ih: amdgpu_ih_ring pointer
410 * Get the IH ring buffer wptr from either the register
411 * or the writeback memory buffer (VEGA20). Also check for
412 * ring buffer overflow and deal with it.
413 * Returns the value of the wptr.
415 static u32 vega20_ih_get_wptr(struct amdgpu_device *adev,
416 struct amdgpu_ih_ring *ih)
419 struct amdgpu_ih_regs *ih_regs;
421 if (ih == &adev->irq.ih || ih == &adev->irq.ih_soft) {
422 /* Only ring0 supports writeback. On other rings fall back
423 * to register-based code with overflow checking below.
424 * ih_soft ring doesn't have any backing hardware registers,
425 * update wptr and return.
427 wptr = le32_to_cpu(*ih->wptr_cpu);
429 if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
433 ih_regs = &ih->ih_regs;
435 /* Double check that the overflow wasn't already cleared. */
436 wptr = RREG32_NO_KIQ(ih_regs->ih_rb_wptr);
437 if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
440 wptr = REG_SET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW, 0);
442 /* When a ring buffer overflow happen start parsing interrupt
443 * from the last not overwritten vector (wptr + 32). Hopefully
444 * this should allow us to catchup.
446 tmp = (wptr + 32) & ih->ptr_mask;
447 dev_warn_ratelimited(adev->dev, "%s ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n",
448 amdgpu_ih_ring_name(adev, ih), wptr, ih->rptr, tmp);
451 tmp = RREG32_NO_KIQ(ih_regs->ih_rb_cntl);
452 tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, WPTR_OVERFLOW_CLEAR, 1);
453 WREG32_NO_KIQ(ih_regs->ih_rb_cntl, tmp);
455 /* Unset the CLEAR_OVERFLOW bit immediately so new overflows
458 tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, WPTR_OVERFLOW_CLEAR, 0);
459 WREG32_NO_KIQ(ih_regs->ih_rb_cntl, tmp);
462 return (wptr & ih->ptr_mask);
466 * vega20_ih_irq_rearm - rearm IRQ if lost
468 * @adev: amdgpu_device pointer
469 * @ih: amdgpu_ih_ring pointer
472 static void vega20_ih_irq_rearm(struct amdgpu_device *adev,
473 struct amdgpu_ih_ring *ih)
477 struct amdgpu_ih_regs *ih_regs;
479 ih_regs = &ih->ih_regs;
481 /* Rearm IRQ / re-wwrite doorbell if doorbell write is lost */
482 for (i = 0; i < MAX_REARM_RETRY; i++) {
483 v = RREG32_NO_KIQ(ih_regs->ih_rb_rptr);
484 if ((v < ih->ring_size) && (v != ih->rptr))
485 WDOORBELL32(ih->doorbell_index, ih->rptr);
492 * vega20_ih_set_rptr - set the IH ring buffer rptr
494 * @adev: amdgpu_device pointer
495 * @ih: amdgpu_ih_ring pointer
497 * Set the IH ring buffer rptr.
499 static void vega20_ih_set_rptr(struct amdgpu_device *adev,
500 struct amdgpu_ih_ring *ih)
502 struct amdgpu_ih_regs *ih_regs;
504 if (ih == &adev->irq.ih_soft)
507 if (ih->use_doorbell) {
508 /* XXX check if swapping is necessary on BE */
509 *ih->rptr_cpu = ih->rptr;
510 WDOORBELL32(ih->doorbell_index, ih->rptr);
512 if (amdgpu_sriov_vf(adev))
513 vega20_ih_irq_rearm(adev, ih);
515 ih_regs = &ih->ih_regs;
516 WREG32(ih_regs->ih_rb_rptr, ih->rptr);
521 * vega20_ih_self_irq - dispatch work for ring 1 and 2
523 * @adev: amdgpu_device pointer
524 * @source: irq source
525 * @entry: IV with WPTR update
527 * Update the WPTR from the IV and schedule work to handle the entries.
529 static int vega20_ih_self_irq(struct amdgpu_device *adev,
530 struct amdgpu_irq_src *source,
531 struct amdgpu_iv_entry *entry)
533 switch (entry->ring_id) {
535 schedule_work(&adev->irq.ih1_work);
538 schedule_work(&adev->irq.ih2_work);
546 static const struct amdgpu_irq_src_funcs vega20_ih_self_irq_funcs = {
547 .process = vega20_ih_self_irq,
550 static void vega20_ih_set_self_irq_funcs(struct amdgpu_device *adev)
552 adev->irq.self_irq.num_types = 0;
553 adev->irq.self_irq.funcs = &vega20_ih_self_irq_funcs;
556 static int vega20_ih_early_init(struct amdgpu_ip_block *ip_block)
558 struct amdgpu_device *adev = ip_block->adev;
560 vega20_ih_set_interrupt_funcs(adev);
561 vega20_ih_set_self_irq_funcs(adev);
565 static int vega20_ih_sw_init(struct amdgpu_ip_block *ip_block)
567 struct amdgpu_device *adev = ip_block->adev;
568 bool use_bus_addr = true;
571 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_IH, 0,
572 &adev->irq.self_irq);
576 if ((adev->flags & AMD_IS_APU) &&
577 (amdgpu_ip_version(adev, OSSSYS_HWIP, 0) == IP_VERSION(4, 4, 2)))
578 use_bus_addr = false;
580 r = amdgpu_ih_ring_init(adev, &adev->irq.ih, IH_RING_SIZE, use_bus_addr);
584 adev->irq.ih.use_doorbell = true;
585 adev->irq.ih.doorbell_index = adev->doorbell_index.ih << 1;
587 r = amdgpu_ih_ring_init(adev, &adev->irq.ih1, PAGE_SIZE, use_bus_addr);
591 adev->irq.ih1.use_doorbell = true;
592 adev->irq.ih1.doorbell_index = (adev->doorbell_index.ih + 1) << 1;
594 if (amdgpu_ip_version(adev, OSSSYS_HWIP, 0) != IP_VERSION(4, 4, 2) &&
595 amdgpu_ip_version(adev, OSSSYS_HWIP, 0) != IP_VERSION(4, 4, 5)) {
596 r = amdgpu_ih_ring_init(adev, &adev->irq.ih2, PAGE_SIZE, true);
600 adev->irq.ih2.use_doorbell = true;
601 adev->irq.ih2.doorbell_index = (adev->doorbell_index.ih + 2) << 1;
604 /* initialize ih control registers offset */
605 vega20_ih_init_register_offset(adev);
607 r = amdgpu_ih_ring_init(adev, &adev->irq.ih_soft, IH_SW_RING_SIZE, use_bus_addr);
611 r = amdgpu_irq_init(adev);
616 static int vega20_ih_sw_fini(struct amdgpu_ip_block *ip_block)
618 struct amdgpu_device *adev = ip_block->adev;
620 amdgpu_irq_fini_sw(adev);
625 static int vega20_ih_hw_init(struct amdgpu_ip_block *ip_block)
628 struct amdgpu_device *adev = ip_block->adev;
630 r = vega20_ih_irq_init(adev);
637 static int vega20_ih_hw_fini(struct amdgpu_ip_block *ip_block)
639 vega20_ih_irq_disable(ip_block->adev);
644 static int vega20_ih_suspend(struct amdgpu_ip_block *ip_block)
646 return vega20_ih_hw_fini(ip_block);
649 static int vega20_ih_resume(struct amdgpu_ip_block *ip_block)
651 return vega20_ih_hw_init(ip_block);
654 static bool vega20_ih_is_idle(void *handle)
660 static int vega20_ih_wait_for_idle(struct amdgpu_ip_block *ip_block)
666 static int vega20_ih_soft_reset(struct amdgpu_ip_block *ip_block)
673 static void vega20_ih_update_clockgating_state(struct amdgpu_device *adev,
676 uint32_t data, def, field_val;
678 if (adev->cg_flags & AMD_CG_SUPPORT_IH_CG) {
679 def = data = RREG32_SOC15(OSSSYS, 0, mmIH_CLK_CTRL);
680 field_val = enable ? 0 : 1;
681 data = REG_SET_FIELD(data, IH_CLK_CTRL,
682 IH_RETRY_INT_CAM_MEM_CLK_SOFT_OVERRIDE, field_val);
683 data = REG_SET_FIELD(data, IH_CLK_CTRL,
684 IH_BUFFER_MEM_CLK_SOFT_OVERRIDE, field_val);
685 data = REG_SET_FIELD(data, IH_CLK_CTRL,
686 DBUS_MUX_CLK_SOFT_OVERRIDE, field_val);
687 data = REG_SET_FIELD(data, IH_CLK_CTRL,
688 OSSSYS_SHARE_CLK_SOFT_OVERRIDE, field_val);
689 data = REG_SET_FIELD(data, IH_CLK_CTRL,
690 LIMIT_SMN_CLK_SOFT_OVERRIDE, field_val);
691 data = REG_SET_FIELD(data, IH_CLK_CTRL,
692 DYN_CLK_SOFT_OVERRIDE, field_val);
693 data = REG_SET_FIELD(data, IH_CLK_CTRL,
694 REG_CLK_SOFT_OVERRIDE, field_val);
696 WREG32_SOC15(OSSSYS, 0, mmIH_CLK_CTRL, data);
700 static int vega20_ih_set_clockgating_state(struct amdgpu_ip_block *ip_block,
701 enum amd_clockgating_state state)
703 struct amdgpu_device *adev = ip_block->adev;
705 vega20_ih_update_clockgating_state(adev,
706 state == AMD_CG_STATE_GATE);
711 static int vega20_ih_set_powergating_state(struct amdgpu_ip_block *ip_block,
712 enum amd_powergating_state state)
717 const struct amd_ip_funcs vega20_ih_ip_funcs = {
719 .early_init = vega20_ih_early_init,
720 .sw_init = vega20_ih_sw_init,
721 .sw_fini = vega20_ih_sw_fini,
722 .hw_init = vega20_ih_hw_init,
723 .hw_fini = vega20_ih_hw_fini,
724 .suspend = vega20_ih_suspend,
725 .resume = vega20_ih_resume,
726 .is_idle = vega20_ih_is_idle,
727 .wait_for_idle = vega20_ih_wait_for_idle,
728 .soft_reset = vega20_ih_soft_reset,
729 .set_clockgating_state = vega20_ih_set_clockgating_state,
730 .set_powergating_state = vega20_ih_set_powergating_state,
733 static const struct amdgpu_ih_funcs vega20_ih_funcs = {
734 .get_wptr = vega20_ih_get_wptr,
735 .decode_iv = amdgpu_ih_decode_iv_helper,
736 .decode_iv_ts = amdgpu_ih_decode_iv_ts_helper,
737 .set_rptr = vega20_ih_set_rptr
740 static void vega20_ih_set_interrupt_funcs(struct amdgpu_device *adev)
742 adev->irq.ih_funcs = &vega20_ih_funcs;
745 const struct amdgpu_ip_block_version vega20_ih_ip_block = {
746 .type = AMD_IP_BLOCK_TYPE_IH,
750 .funcs = &vega20_ih_ip_funcs,