1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright 2014 Advanced Micro Devices, Inc.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
5*4882a593Smuzhiyun * copy of this software and associated documentation files (the "Software"),
6*4882a593Smuzhiyun * to deal in the Software without restriction, including without limitation
7*4882a593Smuzhiyun * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*4882a593Smuzhiyun * and/or sell copies of the Software, and to permit persons to whom the
9*4882a593Smuzhiyun * Software is furnished to do so, subject to the following conditions:
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * The above copyright notice and this permission notice shall be included in
12*4882a593Smuzhiyun * all copies or substantial portions of the Software.
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17*4882a593Smuzhiyun * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*4882a593Smuzhiyun * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*4882a593Smuzhiyun * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*4882a593Smuzhiyun * OTHER DEALINGS IN THE SOFTWARE.
21*4882a593Smuzhiyun *
22*4882a593Smuzhiyun */
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun #include <linux/pci.h>
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun #include "amdgpu.h"
27*4882a593Smuzhiyun #include "amdgpu_ih.h"
28*4882a593Smuzhiyun #include "vid.h"
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #include "oss/oss_3_0_1_d.h"
31*4882a593Smuzhiyun #include "oss/oss_3_0_1_sh_mask.h"
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun #include "bif/bif_5_1_d.h"
34*4882a593Smuzhiyun #include "bif/bif_5_1_sh_mask.h"
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun /*
37*4882a593Smuzhiyun * Interrupts
38*4882a593Smuzhiyun * Starting with r6xx, interrupts are handled via a ring buffer.
39*4882a593Smuzhiyun * Ring buffers are areas of GPU accessible memory that the GPU
40*4882a593Smuzhiyun * writes interrupt vectors into and the host reads vectors out of.
41*4882a593Smuzhiyun * There is a rptr (read pointer) that determines where the
42*4882a593Smuzhiyun * host is currently reading, and a wptr (write pointer)
43*4882a593Smuzhiyun * which determines where the GPU has written. When the
44*4882a593Smuzhiyun * pointers are equal, the ring is idle. When the GPU
45*4882a593Smuzhiyun * writes vectors to the ring buffer, it increments the
46*4882a593Smuzhiyun * wptr. When there is an interrupt, the host then starts
47*4882a593Smuzhiyun * fetching commands and processing them until the pointers are
48*4882a593Smuzhiyun * equal again at which point it updates the rptr.
49*4882a593Smuzhiyun */
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun static void cz_ih_set_interrupt_funcs(struct amdgpu_device *adev);
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun /**
54*4882a593Smuzhiyun * cz_ih_enable_interrupts - Enable the interrupt ring buffer
55*4882a593Smuzhiyun *
56*4882a593Smuzhiyun * @adev: amdgpu_device pointer
57*4882a593Smuzhiyun *
58*4882a593Smuzhiyun * Enable the interrupt ring buffer (VI).
59*4882a593Smuzhiyun */
cz_ih_enable_interrupts(struct amdgpu_device * adev)60*4882a593Smuzhiyun static void cz_ih_enable_interrupts(struct amdgpu_device *adev)
61*4882a593Smuzhiyun {
62*4882a593Smuzhiyun u32 ih_cntl = RREG32(mmIH_CNTL);
63*4882a593Smuzhiyun u32 ih_rb_cntl = RREG32(mmIH_RB_CNTL);
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun ih_cntl = REG_SET_FIELD(ih_cntl, IH_CNTL, ENABLE_INTR, 1);
66*4882a593Smuzhiyun ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, RB_ENABLE, 1);
67*4882a593Smuzhiyun WREG32(mmIH_CNTL, ih_cntl);
68*4882a593Smuzhiyun WREG32(mmIH_RB_CNTL, ih_rb_cntl);
69*4882a593Smuzhiyun adev->irq.ih.enabled = true;
70*4882a593Smuzhiyun }
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun /**
73*4882a593Smuzhiyun * cz_ih_disable_interrupts - Disable the interrupt ring buffer
74*4882a593Smuzhiyun *
75*4882a593Smuzhiyun * @adev: amdgpu_device pointer
76*4882a593Smuzhiyun *
77*4882a593Smuzhiyun * Disable the interrupt ring buffer (VI).
78*4882a593Smuzhiyun */
cz_ih_disable_interrupts(struct amdgpu_device * adev)79*4882a593Smuzhiyun static void cz_ih_disable_interrupts(struct amdgpu_device *adev)
80*4882a593Smuzhiyun {
81*4882a593Smuzhiyun u32 ih_rb_cntl = RREG32(mmIH_RB_CNTL);
82*4882a593Smuzhiyun u32 ih_cntl = RREG32(mmIH_CNTL);
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, RB_ENABLE, 0);
85*4882a593Smuzhiyun ih_cntl = REG_SET_FIELD(ih_cntl, IH_CNTL, ENABLE_INTR, 0);
86*4882a593Smuzhiyun WREG32(mmIH_RB_CNTL, ih_rb_cntl);
87*4882a593Smuzhiyun WREG32(mmIH_CNTL, ih_cntl);
88*4882a593Smuzhiyun /* set rptr, wptr to 0 */
89*4882a593Smuzhiyun WREG32(mmIH_RB_RPTR, 0);
90*4882a593Smuzhiyun WREG32(mmIH_RB_WPTR, 0);
91*4882a593Smuzhiyun adev->irq.ih.enabled = false;
92*4882a593Smuzhiyun adev->irq.ih.rptr = 0;
93*4882a593Smuzhiyun }
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun /**
96*4882a593Smuzhiyun * cz_ih_irq_init - init and enable the interrupt ring
97*4882a593Smuzhiyun *
98*4882a593Smuzhiyun * @adev: amdgpu_device pointer
99*4882a593Smuzhiyun *
100*4882a593Smuzhiyun * Allocate a ring buffer for the interrupt controller,
101*4882a593Smuzhiyun * enable the RLC, disable interrupts, enable the IH
102*4882a593Smuzhiyun * ring buffer and enable it (VI).
103*4882a593Smuzhiyun * Called at device load and reume.
104*4882a593Smuzhiyun * Returns 0 for success, errors for failure.
105*4882a593Smuzhiyun */
cz_ih_irq_init(struct amdgpu_device * adev)106*4882a593Smuzhiyun static int cz_ih_irq_init(struct amdgpu_device *adev)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun struct amdgpu_ih_ring *ih = &adev->irq.ih;
109*4882a593Smuzhiyun u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
110*4882a593Smuzhiyun int rb_bufsz;
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun /* disable irqs */
113*4882a593Smuzhiyun cz_ih_disable_interrupts(adev);
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun /* setup interrupt control */
116*4882a593Smuzhiyun WREG32(mmINTERRUPT_CNTL2, adev->dummy_page_addr >> 8);
117*4882a593Smuzhiyun interrupt_cntl = RREG32(mmINTERRUPT_CNTL);
118*4882a593Smuzhiyun /* INTERRUPT_CNTL__IH_DUMMY_RD_OVERRIDE_MASK=0 - dummy read disabled with msi, enabled without msi
119*4882a593Smuzhiyun * INTERRUPT_CNTL__IH_DUMMY_RD_OVERRIDE_MASK=1 - dummy read controlled by IH_DUMMY_RD_EN
120*4882a593Smuzhiyun */
121*4882a593Smuzhiyun interrupt_cntl = REG_SET_FIELD(interrupt_cntl, INTERRUPT_CNTL, IH_DUMMY_RD_OVERRIDE, 0);
122*4882a593Smuzhiyun /* INTERRUPT_CNTL__IH_REQ_NONSNOOP_EN_MASK=1 if ring is in non-cacheable memory, e.g., vram */
123*4882a593Smuzhiyun interrupt_cntl = REG_SET_FIELD(interrupt_cntl, INTERRUPT_CNTL, IH_REQ_NONSNOOP_EN, 0);
124*4882a593Smuzhiyun WREG32(mmINTERRUPT_CNTL, interrupt_cntl);
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun /* Ring Buffer base. [39:8] of 40-bit address of the beginning of the ring buffer*/
127*4882a593Smuzhiyun WREG32(mmIH_RB_BASE, adev->irq.ih.gpu_addr >> 8);
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun rb_bufsz = order_base_2(adev->irq.ih.ring_size / 4);
130*4882a593Smuzhiyun ih_rb_cntl = REG_SET_FIELD(0, IH_RB_CNTL, WPTR_OVERFLOW_ENABLE, 1);
131*4882a593Smuzhiyun ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, WPTR_OVERFLOW_CLEAR, 1);
132*4882a593Smuzhiyun ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, RB_SIZE, rb_bufsz);
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun /* Ring Buffer write pointer writeback. If enabled, IH_RB_WPTR register value is written to memory */
135*4882a593Smuzhiyun ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, WPTR_WRITEBACK_ENABLE, 1);
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun /* set the writeback address whether it's enabled or not */
138*4882a593Smuzhiyun WREG32(mmIH_RB_WPTR_ADDR_LO, lower_32_bits(ih->wptr_addr));
139*4882a593Smuzhiyun WREG32(mmIH_RB_WPTR_ADDR_HI, upper_32_bits(ih->wptr_addr) & 0xFF);
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun WREG32(mmIH_RB_CNTL, ih_rb_cntl);
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun /* set rptr, wptr to 0 */
144*4882a593Smuzhiyun WREG32(mmIH_RB_RPTR, 0);
145*4882a593Smuzhiyun WREG32(mmIH_RB_WPTR, 0);
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun /* Default settings for IH_CNTL (disabled at first) */
148*4882a593Smuzhiyun ih_cntl = RREG32(mmIH_CNTL);
149*4882a593Smuzhiyun ih_cntl = REG_SET_FIELD(ih_cntl, IH_CNTL, MC_VMID, 0);
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun if (adev->irq.msi_enabled)
152*4882a593Smuzhiyun ih_cntl = REG_SET_FIELD(ih_cntl, IH_CNTL, RPTR_REARM, 1);
153*4882a593Smuzhiyun WREG32(mmIH_CNTL, ih_cntl);
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun pci_set_master(adev->pdev);
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun /* enable interrupts */
158*4882a593Smuzhiyun cz_ih_enable_interrupts(adev);
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun return 0;
161*4882a593Smuzhiyun }
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun /**
164*4882a593Smuzhiyun * cz_ih_irq_disable - disable interrupts
165*4882a593Smuzhiyun *
166*4882a593Smuzhiyun * @adev: amdgpu_device pointer
167*4882a593Smuzhiyun *
168*4882a593Smuzhiyun * Disable interrupts on the hw (VI).
169*4882a593Smuzhiyun */
cz_ih_irq_disable(struct amdgpu_device * adev)170*4882a593Smuzhiyun static void cz_ih_irq_disable(struct amdgpu_device *adev)
171*4882a593Smuzhiyun {
172*4882a593Smuzhiyun cz_ih_disable_interrupts(adev);
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun /* Wait and acknowledge irq */
175*4882a593Smuzhiyun mdelay(1);
176*4882a593Smuzhiyun }
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun /**
179*4882a593Smuzhiyun * cz_ih_get_wptr - get the IH ring buffer wptr
180*4882a593Smuzhiyun *
181*4882a593Smuzhiyun * @adev: amdgpu_device pointer
182*4882a593Smuzhiyun *
183*4882a593Smuzhiyun * Get the IH ring buffer wptr from either the register
184*4882a593Smuzhiyun * or the writeback memory buffer (VI). Also check for
185*4882a593Smuzhiyun * ring buffer overflow and deal with it.
186*4882a593Smuzhiyun * Used by cz_irq_process(VI).
187*4882a593Smuzhiyun * Returns the value of the wptr.
188*4882a593Smuzhiyun */
cz_ih_get_wptr(struct amdgpu_device * adev,struct amdgpu_ih_ring * ih)189*4882a593Smuzhiyun static u32 cz_ih_get_wptr(struct amdgpu_device *adev,
190*4882a593Smuzhiyun struct amdgpu_ih_ring *ih)
191*4882a593Smuzhiyun {
192*4882a593Smuzhiyun u32 wptr, tmp;
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun wptr = le32_to_cpu(*ih->wptr_cpu);
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
197*4882a593Smuzhiyun goto out;
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun /* Double check that the overflow wasn't already cleared. */
200*4882a593Smuzhiyun wptr = RREG32(mmIH_RB_WPTR);
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
203*4882a593Smuzhiyun goto out;
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun wptr = REG_SET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW, 0);
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun /* When a ring buffer overflow happen start parsing interrupt
208*4882a593Smuzhiyun * from the last not overwritten vector (wptr + 16). Hopefully
209*4882a593Smuzhiyun * this should allow us to catchup.
210*4882a593Smuzhiyun */
211*4882a593Smuzhiyun dev_warn(adev->dev, "IH ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n",
212*4882a593Smuzhiyun wptr, ih->rptr, (wptr + 16) & ih->ptr_mask);
213*4882a593Smuzhiyun ih->rptr = (wptr + 16) & ih->ptr_mask;
214*4882a593Smuzhiyun tmp = RREG32(mmIH_RB_CNTL);
215*4882a593Smuzhiyun tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, WPTR_OVERFLOW_CLEAR, 1);
216*4882a593Smuzhiyun WREG32(mmIH_RB_CNTL, tmp);
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun
219*4882a593Smuzhiyun out:
220*4882a593Smuzhiyun return (wptr & ih->ptr_mask);
221*4882a593Smuzhiyun }
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun /**
224*4882a593Smuzhiyun * cz_ih_decode_iv - decode an interrupt vector
225*4882a593Smuzhiyun *
226*4882a593Smuzhiyun * @adev: amdgpu_device pointer
227*4882a593Smuzhiyun *
228*4882a593Smuzhiyun * Decodes the interrupt vector at the current rptr
229*4882a593Smuzhiyun * position and also advance the position.
230*4882a593Smuzhiyun */
cz_ih_decode_iv(struct amdgpu_device * adev,struct amdgpu_ih_ring * ih,struct amdgpu_iv_entry * entry)231*4882a593Smuzhiyun static void cz_ih_decode_iv(struct amdgpu_device *adev,
232*4882a593Smuzhiyun struct amdgpu_ih_ring *ih,
233*4882a593Smuzhiyun struct amdgpu_iv_entry *entry)
234*4882a593Smuzhiyun {
235*4882a593Smuzhiyun /* wptr/rptr are in bytes! */
236*4882a593Smuzhiyun u32 ring_index = ih->rptr >> 2;
237*4882a593Smuzhiyun uint32_t dw[4];
238*4882a593Smuzhiyun
239*4882a593Smuzhiyun dw[0] = le32_to_cpu(ih->ring[ring_index + 0]);
240*4882a593Smuzhiyun dw[1] = le32_to_cpu(ih->ring[ring_index + 1]);
241*4882a593Smuzhiyun dw[2] = le32_to_cpu(ih->ring[ring_index + 2]);
242*4882a593Smuzhiyun dw[3] = le32_to_cpu(ih->ring[ring_index + 3]);
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun entry->client_id = AMDGPU_IRQ_CLIENTID_LEGACY;
245*4882a593Smuzhiyun entry->src_id = dw[0] & 0xff;
246*4882a593Smuzhiyun entry->src_data[0] = dw[1] & 0xfffffff;
247*4882a593Smuzhiyun entry->ring_id = dw[2] & 0xff;
248*4882a593Smuzhiyun entry->vmid = (dw[2] >> 8) & 0xff;
249*4882a593Smuzhiyun entry->pasid = (dw[2] >> 16) & 0xffff;
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun /* wptr/rptr are in bytes! */
252*4882a593Smuzhiyun ih->rptr += 16;
253*4882a593Smuzhiyun }
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun /**
256*4882a593Smuzhiyun * cz_ih_set_rptr - set the IH ring buffer rptr
257*4882a593Smuzhiyun *
258*4882a593Smuzhiyun * @adev: amdgpu_device pointer
259*4882a593Smuzhiyun *
260*4882a593Smuzhiyun * Set the IH ring buffer rptr.
261*4882a593Smuzhiyun */
cz_ih_set_rptr(struct amdgpu_device * adev,struct amdgpu_ih_ring * ih)262*4882a593Smuzhiyun static void cz_ih_set_rptr(struct amdgpu_device *adev,
263*4882a593Smuzhiyun struct amdgpu_ih_ring *ih)
264*4882a593Smuzhiyun {
265*4882a593Smuzhiyun WREG32(mmIH_RB_RPTR, ih->rptr);
266*4882a593Smuzhiyun }
267*4882a593Smuzhiyun
cz_ih_early_init(void * handle)268*4882a593Smuzhiyun static int cz_ih_early_init(void *handle)
269*4882a593Smuzhiyun {
270*4882a593Smuzhiyun struct amdgpu_device *adev = (struct amdgpu_device *)handle;
271*4882a593Smuzhiyun int ret;
272*4882a593Smuzhiyun
273*4882a593Smuzhiyun ret = amdgpu_irq_add_domain(adev);
274*4882a593Smuzhiyun if (ret)
275*4882a593Smuzhiyun return ret;
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun cz_ih_set_interrupt_funcs(adev);
278*4882a593Smuzhiyun
279*4882a593Smuzhiyun return 0;
280*4882a593Smuzhiyun }
281*4882a593Smuzhiyun
cz_ih_sw_init(void * handle)282*4882a593Smuzhiyun static int cz_ih_sw_init(void *handle)
283*4882a593Smuzhiyun {
284*4882a593Smuzhiyun int r;
285*4882a593Smuzhiyun struct amdgpu_device *adev = (struct amdgpu_device *)handle;
286*4882a593Smuzhiyun
287*4882a593Smuzhiyun r = amdgpu_ih_ring_init(adev, &adev->irq.ih, 64 * 1024, false);
288*4882a593Smuzhiyun if (r)
289*4882a593Smuzhiyun return r;
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun r = amdgpu_irq_init(adev);
292*4882a593Smuzhiyun
293*4882a593Smuzhiyun return r;
294*4882a593Smuzhiyun }
295*4882a593Smuzhiyun
cz_ih_sw_fini(void * handle)296*4882a593Smuzhiyun static int cz_ih_sw_fini(void *handle)
297*4882a593Smuzhiyun {
298*4882a593Smuzhiyun struct amdgpu_device *adev = (struct amdgpu_device *)handle;
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun amdgpu_irq_fini(adev);
301*4882a593Smuzhiyun amdgpu_ih_ring_fini(adev, &adev->irq.ih);
302*4882a593Smuzhiyun amdgpu_irq_remove_domain(adev);
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun return 0;
305*4882a593Smuzhiyun }
306*4882a593Smuzhiyun
cz_ih_hw_init(void * handle)307*4882a593Smuzhiyun static int cz_ih_hw_init(void *handle)
308*4882a593Smuzhiyun {
309*4882a593Smuzhiyun int r;
310*4882a593Smuzhiyun struct amdgpu_device *adev = (struct amdgpu_device *)handle;
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun r = cz_ih_irq_init(adev);
313*4882a593Smuzhiyun if (r)
314*4882a593Smuzhiyun return r;
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun return 0;
317*4882a593Smuzhiyun }
318*4882a593Smuzhiyun
cz_ih_hw_fini(void * handle)319*4882a593Smuzhiyun static int cz_ih_hw_fini(void *handle)
320*4882a593Smuzhiyun {
321*4882a593Smuzhiyun struct amdgpu_device *adev = (struct amdgpu_device *)handle;
322*4882a593Smuzhiyun
323*4882a593Smuzhiyun cz_ih_irq_disable(adev);
324*4882a593Smuzhiyun
325*4882a593Smuzhiyun return 0;
326*4882a593Smuzhiyun }
327*4882a593Smuzhiyun
cz_ih_suspend(void * handle)328*4882a593Smuzhiyun static int cz_ih_suspend(void *handle)
329*4882a593Smuzhiyun {
330*4882a593Smuzhiyun struct amdgpu_device *adev = (struct amdgpu_device *)handle;
331*4882a593Smuzhiyun
332*4882a593Smuzhiyun return cz_ih_hw_fini(adev);
333*4882a593Smuzhiyun }
334*4882a593Smuzhiyun
cz_ih_resume(void * handle)335*4882a593Smuzhiyun static int cz_ih_resume(void *handle)
336*4882a593Smuzhiyun {
337*4882a593Smuzhiyun struct amdgpu_device *adev = (struct amdgpu_device *)handle;
338*4882a593Smuzhiyun
339*4882a593Smuzhiyun return cz_ih_hw_init(adev);
340*4882a593Smuzhiyun }
341*4882a593Smuzhiyun
cz_ih_is_idle(void * handle)342*4882a593Smuzhiyun static bool cz_ih_is_idle(void *handle)
343*4882a593Smuzhiyun {
344*4882a593Smuzhiyun struct amdgpu_device *adev = (struct amdgpu_device *)handle;
345*4882a593Smuzhiyun u32 tmp = RREG32(mmSRBM_STATUS);
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun if (REG_GET_FIELD(tmp, SRBM_STATUS, IH_BUSY))
348*4882a593Smuzhiyun return false;
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun return true;
351*4882a593Smuzhiyun }
352*4882a593Smuzhiyun
cz_ih_wait_for_idle(void * handle)353*4882a593Smuzhiyun static int cz_ih_wait_for_idle(void *handle)
354*4882a593Smuzhiyun {
355*4882a593Smuzhiyun unsigned i;
356*4882a593Smuzhiyun u32 tmp;
357*4882a593Smuzhiyun struct amdgpu_device *adev = (struct amdgpu_device *)handle;
358*4882a593Smuzhiyun
359*4882a593Smuzhiyun for (i = 0; i < adev->usec_timeout; i++) {
360*4882a593Smuzhiyun /* read MC_STATUS */
361*4882a593Smuzhiyun tmp = RREG32(mmSRBM_STATUS);
362*4882a593Smuzhiyun if (!REG_GET_FIELD(tmp, SRBM_STATUS, IH_BUSY))
363*4882a593Smuzhiyun return 0;
364*4882a593Smuzhiyun udelay(1);
365*4882a593Smuzhiyun }
366*4882a593Smuzhiyun return -ETIMEDOUT;
367*4882a593Smuzhiyun }
368*4882a593Smuzhiyun
cz_ih_soft_reset(void * handle)369*4882a593Smuzhiyun static int cz_ih_soft_reset(void *handle)
370*4882a593Smuzhiyun {
371*4882a593Smuzhiyun u32 srbm_soft_reset = 0;
372*4882a593Smuzhiyun struct amdgpu_device *adev = (struct amdgpu_device *)handle;
373*4882a593Smuzhiyun u32 tmp = RREG32(mmSRBM_STATUS);
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun if (tmp & SRBM_STATUS__IH_BUSY_MASK)
376*4882a593Smuzhiyun srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET,
377*4882a593Smuzhiyun SOFT_RESET_IH, 1);
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun if (srbm_soft_reset) {
380*4882a593Smuzhiyun tmp = RREG32(mmSRBM_SOFT_RESET);
381*4882a593Smuzhiyun tmp |= srbm_soft_reset;
382*4882a593Smuzhiyun dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
383*4882a593Smuzhiyun WREG32(mmSRBM_SOFT_RESET, tmp);
384*4882a593Smuzhiyun tmp = RREG32(mmSRBM_SOFT_RESET);
385*4882a593Smuzhiyun
386*4882a593Smuzhiyun udelay(50);
387*4882a593Smuzhiyun
388*4882a593Smuzhiyun tmp &= ~srbm_soft_reset;
389*4882a593Smuzhiyun WREG32(mmSRBM_SOFT_RESET, tmp);
390*4882a593Smuzhiyun tmp = RREG32(mmSRBM_SOFT_RESET);
391*4882a593Smuzhiyun
392*4882a593Smuzhiyun /* Wait a little for things to settle down */
393*4882a593Smuzhiyun udelay(50);
394*4882a593Smuzhiyun }
395*4882a593Smuzhiyun
396*4882a593Smuzhiyun return 0;
397*4882a593Smuzhiyun }
398*4882a593Smuzhiyun
cz_ih_set_clockgating_state(void * handle,enum amd_clockgating_state state)399*4882a593Smuzhiyun static int cz_ih_set_clockgating_state(void *handle,
400*4882a593Smuzhiyun enum amd_clockgating_state state)
401*4882a593Smuzhiyun {
402*4882a593Smuzhiyun // TODO
403*4882a593Smuzhiyun return 0;
404*4882a593Smuzhiyun }
405*4882a593Smuzhiyun
cz_ih_set_powergating_state(void * handle,enum amd_powergating_state state)406*4882a593Smuzhiyun static int cz_ih_set_powergating_state(void *handle,
407*4882a593Smuzhiyun enum amd_powergating_state state)
408*4882a593Smuzhiyun {
409*4882a593Smuzhiyun // TODO
410*4882a593Smuzhiyun return 0;
411*4882a593Smuzhiyun }
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun static const struct amd_ip_funcs cz_ih_ip_funcs = {
414*4882a593Smuzhiyun .name = "cz_ih",
415*4882a593Smuzhiyun .early_init = cz_ih_early_init,
416*4882a593Smuzhiyun .late_init = NULL,
417*4882a593Smuzhiyun .sw_init = cz_ih_sw_init,
418*4882a593Smuzhiyun .sw_fini = cz_ih_sw_fini,
419*4882a593Smuzhiyun .hw_init = cz_ih_hw_init,
420*4882a593Smuzhiyun .hw_fini = cz_ih_hw_fini,
421*4882a593Smuzhiyun .suspend = cz_ih_suspend,
422*4882a593Smuzhiyun .resume = cz_ih_resume,
423*4882a593Smuzhiyun .is_idle = cz_ih_is_idle,
424*4882a593Smuzhiyun .wait_for_idle = cz_ih_wait_for_idle,
425*4882a593Smuzhiyun .soft_reset = cz_ih_soft_reset,
426*4882a593Smuzhiyun .set_clockgating_state = cz_ih_set_clockgating_state,
427*4882a593Smuzhiyun .set_powergating_state = cz_ih_set_powergating_state,
428*4882a593Smuzhiyun };
429*4882a593Smuzhiyun
430*4882a593Smuzhiyun static const struct amdgpu_ih_funcs cz_ih_funcs = {
431*4882a593Smuzhiyun .get_wptr = cz_ih_get_wptr,
432*4882a593Smuzhiyun .decode_iv = cz_ih_decode_iv,
433*4882a593Smuzhiyun .set_rptr = cz_ih_set_rptr
434*4882a593Smuzhiyun };
435*4882a593Smuzhiyun
cz_ih_set_interrupt_funcs(struct amdgpu_device * adev)436*4882a593Smuzhiyun static void cz_ih_set_interrupt_funcs(struct amdgpu_device *adev)
437*4882a593Smuzhiyun {
438*4882a593Smuzhiyun adev->irq.ih_funcs = &cz_ih_funcs;
439*4882a593Smuzhiyun }
440*4882a593Smuzhiyun
441*4882a593Smuzhiyun const struct amdgpu_ip_block_version cz_ih_ip_block =
442*4882a593Smuzhiyun {
443*4882a593Smuzhiyun .type = AMD_IP_BLOCK_TYPE_IH,
444*4882a593Smuzhiyun .major = 3,
445*4882a593Smuzhiyun .minor = 0,
446*4882a593Smuzhiyun .rev = 0,
447*4882a593Smuzhiyun .funcs = &cz_ih_ip_funcs,
448*4882a593Smuzhiyun };
449