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