1fb4d8502Sjsg /*
2fb4d8502Sjsg * Copyright 2012 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 "cikd.h"
29fb4d8502Sjsg
30fb4d8502Sjsg #include "bif/bif_4_1_d.h"
31fb4d8502Sjsg #include "bif/bif_4_1_sh_mask.h"
32fb4d8502Sjsg
33fb4d8502Sjsg #include "oss/oss_2_0_d.h"
34fb4d8502Sjsg #include "oss/oss_2_0_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 cik_ih_set_interrupt_funcs(struct amdgpu_device *adev);
52fb4d8502Sjsg
53fb4d8502Sjsg /**
54fb4d8502Sjsg * cik_ih_enable_interrupts - Enable the interrupt ring buffer
55fb4d8502Sjsg *
56fb4d8502Sjsg * @adev: amdgpu_device pointer
57fb4d8502Sjsg *
58fb4d8502Sjsg * Enable the interrupt ring buffer (CIK).
59fb4d8502Sjsg */
cik_ih_enable_interrupts(struct amdgpu_device * adev)60fb4d8502Sjsg static void cik_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 |= IH_CNTL__ENABLE_INTR_MASK;
66fb4d8502Sjsg ih_rb_cntl |= IH_RB_CNTL__RB_ENABLE_MASK;
67fb4d8502Sjsg WREG32(mmIH_CNTL, ih_cntl);
68fb4d8502Sjsg WREG32(mmIH_RB_CNTL, ih_rb_cntl);
69fb4d8502Sjsg adev->irq.ih.enabled = true;
70fb4d8502Sjsg }
71fb4d8502Sjsg
72fb4d8502Sjsg /**
73fb4d8502Sjsg * cik_ih_disable_interrupts - Disable the interrupt ring buffer
74fb4d8502Sjsg *
75fb4d8502Sjsg * @adev: amdgpu_device pointer
76fb4d8502Sjsg *
77fb4d8502Sjsg * Disable the interrupt ring buffer (CIK).
78fb4d8502Sjsg */
cik_ih_disable_interrupts(struct amdgpu_device * adev)79fb4d8502Sjsg static void cik_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 &= ~IH_RB_CNTL__RB_ENABLE_MASK;
85fb4d8502Sjsg ih_cntl &= ~IH_CNTL__ENABLE_INTR_MASK;
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 * cik_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 (CIK).
103fb4d8502Sjsg * Called at device load and reume.
104fb4d8502Sjsg * Returns 0 for success, errors for failure.
105fb4d8502Sjsg */
cik_ih_irq_init(struct amdgpu_device * adev)106fb4d8502Sjsg static int cik_ih_irq_init(struct amdgpu_device *adev)
107fb4d8502Sjsg {
108c349dbc7Sjsg struct amdgpu_ih_ring *ih = &adev->irq.ih;
109fb4d8502Sjsg int rb_bufsz;
110fb4d8502Sjsg u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
111fb4d8502Sjsg
112fb4d8502Sjsg /* disable irqs */
113fb4d8502Sjsg cik_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 &= ~INTERRUPT_CNTL__IH_DUMMY_RD_OVERRIDE_MASK;
122fb4d8502Sjsg /* INTERRUPT_CNTL__IH_REQ_NONSNOOP_EN_MASK=1 if ring is in non-cacheable memory, e.g., vram */
123fb4d8502Sjsg interrupt_cntl &= ~INTERRUPT_CNTL__IH_REQ_NONSNOOP_EN_MASK;
124fb4d8502Sjsg WREG32(mmINTERRUPT_CNTL, interrupt_cntl);
125fb4d8502Sjsg
126fb4d8502Sjsg WREG32(mmIH_RB_BASE, adev->irq.ih.gpu_addr >> 8);
127fb4d8502Sjsg rb_bufsz = order_base_2(adev->irq.ih.ring_size / 4);
128fb4d8502Sjsg
129fb4d8502Sjsg ih_rb_cntl = (IH_RB_CNTL__WPTR_OVERFLOW_ENABLE_MASK |
130fb4d8502Sjsg IH_RB_CNTL__WPTR_OVERFLOW_CLEAR_MASK |
131fb4d8502Sjsg (rb_bufsz << 1));
132fb4d8502Sjsg
133fb4d8502Sjsg ih_rb_cntl |= IH_RB_CNTL__WPTR_WRITEBACK_ENABLE_MASK;
134fb4d8502Sjsg
135fb4d8502Sjsg /* set the writeback address whether it's enabled or not */
136c349dbc7Sjsg WREG32(mmIH_RB_WPTR_ADDR_LO, lower_32_bits(ih->wptr_addr));
137c349dbc7Sjsg WREG32(mmIH_RB_WPTR_ADDR_HI, upper_32_bits(ih->wptr_addr) & 0xFF);
138fb4d8502Sjsg
139fb4d8502Sjsg WREG32(mmIH_RB_CNTL, ih_rb_cntl);
140fb4d8502Sjsg
141fb4d8502Sjsg /* set rptr, wptr to 0 */
142fb4d8502Sjsg WREG32(mmIH_RB_RPTR, 0);
143fb4d8502Sjsg WREG32(mmIH_RB_WPTR, 0);
144fb4d8502Sjsg
145fb4d8502Sjsg /* Default settings for IH_CNTL (disabled at first) */
146fb4d8502Sjsg ih_cntl = (0x10 << IH_CNTL__MC_WRREQ_CREDIT__SHIFT) |
147fb4d8502Sjsg (0x10 << IH_CNTL__MC_WR_CLEAN_CNT__SHIFT) |
148fb4d8502Sjsg (0 << IH_CNTL__MC_VMID__SHIFT);
149fb4d8502Sjsg /* IH_CNTL__RPTR_REARM_MASK only works if msi's are enabled */
150fb4d8502Sjsg if (adev->irq.msi_enabled)
151fb4d8502Sjsg ih_cntl |= IH_CNTL__RPTR_REARM_MASK;
152fb4d8502Sjsg WREG32(mmIH_CNTL, ih_cntl);
153fb4d8502Sjsg
154fb4d8502Sjsg pci_set_master(adev->pdev);
155fb4d8502Sjsg
156fb4d8502Sjsg /* enable irqs */
157fb4d8502Sjsg cik_ih_enable_interrupts(adev);
158fb4d8502Sjsg
159fb4d8502Sjsg return 0;
160fb4d8502Sjsg }
161fb4d8502Sjsg
162fb4d8502Sjsg /**
163fb4d8502Sjsg * cik_ih_irq_disable - disable interrupts
164fb4d8502Sjsg *
165fb4d8502Sjsg * @adev: amdgpu_device pointer
166fb4d8502Sjsg *
167fb4d8502Sjsg * Disable interrupts on the hw (CIK).
168fb4d8502Sjsg */
cik_ih_irq_disable(struct amdgpu_device * adev)169fb4d8502Sjsg static void cik_ih_irq_disable(struct amdgpu_device *adev)
170fb4d8502Sjsg {
171fb4d8502Sjsg cik_ih_disable_interrupts(adev);
172fb4d8502Sjsg /* Wait and acknowledge irq */
173fb4d8502Sjsg mdelay(1);
174fb4d8502Sjsg }
175fb4d8502Sjsg
176fb4d8502Sjsg /**
177fb4d8502Sjsg * cik_ih_get_wptr - get the IH ring buffer wptr
178fb4d8502Sjsg *
179fb4d8502Sjsg * @adev: amdgpu_device pointer
1805ca02815Sjsg * @ih: IH ring buffer to fetch wptr
181fb4d8502Sjsg *
182fb4d8502Sjsg * Get the IH ring buffer wptr from either the register
183fb4d8502Sjsg * or the writeback memory buffer (CIK). Also check for
184fb4d8502Sjsg * ring buffer overflow and deal with it.
185fb4d8502Sjsg * Used by cik_irq_process().
186fb4d8502Sjsg * Returns the value of the wptr.
187fb4d8502Sjsg */
cik_ih_get_wptr(struct amdgpu_device * adev,struct amdgpu_ih_ring * ih)188c349dbc7Sjsg static u32 cik_ih_get_wptr(struct amdgpu_device *adev,
189c349dbc7Sjsg struct amdgpu_ih_ring *ih)
190fb4d8502Sjsg {
191fb4d8502Sjsg u32 wptr, tmp;
192fb4d8502Sjsg
193c349dbc7Sjsg wptr = le32_to_cpu(*ih->wptr_cpu);
194fb4d8502Sjsg
195fb4d8502Sjsg if (wptr & IH_RB_WPTR__RB_OVERFLOW_MASK) {
196fb4d8502Sjsg wptr &= ~IH_RB_WPTR__RB_OVERFLOW_MASK;
197fb4d8502Sjsg /* When a ring buffer overflow happen start parsing interrupt
198fb4d8502Sjsg * from the last not overwritten vector (wptr + 16). Hopefully
199fb4d8502Sjsg * this should allow us to catchup.
200fb4d8502Sjsg */
201fb4d8502Sjsg dev_warn(adev->dev, "IH ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n",
202c349dbc7Sjsg wptr, ih->rptr, (wptr + 16) & ih->ptr_mask);
203c349dbc7Sjsg ih->rptr = (wptr + 16) & ih->ptr_mask;
204fb4d8502Sjsg tmp = RREG32(mmIH_RB_CNTL);
205fb4d8502Sjsg tmp |= IH_RB_CNTL__WPTR_OVERFLOW_CLEAR_MASK;
206fb4d8502Sjsg WREG32(mmIH_RB_CNTL, tmp);
207*f7a572c7Sjsg
208*f7a572c7Sjsg /* Unset the CLEAR_OVERFLOW bit immediately so new overflows
209*f7a572c7Sjsg * can be detected.
210*f7a572c7Sjsg */
211*f7a572c7Sjsg tmp &= ~IH_RB_CNTL__WPTR_OVERFLOW_CLEAR_MASK;
212*f7a572c7Sjsg WREG32(mmIH_RB_CNTL, tmp);
213fb4d8502Sjsg }
214c349dbc7Sjsg return (wptr & ih->ptr_mask);
215fb4d8502Sjsg }
216fb4d8502Sjsg
217fb4d8502Sjsg /* CIK IV Ring
218fb4d8502Sjsg * Each IV ring entry is 128 bits:
219fb4d8502Sjsg * [7:0] - interrupt source id
220fb4d8502Sjsg * [31:8] - reserved
221fb4d8502Sjsg * [59:32] - interrupt source data
222fb4d8502Sjsg * [63:60] - reserved
223fb4d8502Sjsg * [71:64] - RINGID
224fb4d8502Sjsg * CP:
225fb4d8502Sjsg * ME_ID [1:0], PIPE_ID[1:0], QUEUE_ID[2:0]
226fb4d8502Sjsg * QUEUE_ID - for compute, which of the 8 queues owned by the dispatcher
227fb4d8502Sjsg * - for gfx, hw shader state (0=PS...5=LS, 6=CS)
228fb4d8502Sjsg * ME_ID - 0 = gfx, 1 = first 4 CS pipes, 2 = second 4 CS pipes
229fb4d8502Sjsg * PIPE_ID - ME0 0=3D
230fb4d8502Sjsg * - ME1&2 compute dispatcher (4 pipes each)
231fb4d8502Sjsg * SDMA:
232fb4d8502Sjsg * INSTANCE_ID [1:0], QUEUE_ID[1:0]
233fb4d8502Sjsg * INSTANCE_ID - 0 = sdma0, 1 = sdma1
234fb4d8502Sjsg * QUEUE_ID - 0 = gfx, 1 = rlc0, 2 = rlc1
235fb4d8502Sjsg * [79:72] - VMID
236fb4d8502Sjsg * [95:80] - PASID
237fb4d8502Sjsg * [127:96] - reserved
238fb4d8502Sjsg */
239fb4d8502Sjsg
240fb4d8502Sjsg /**
241fb4d8502Sjsg * cik_ih_decode_iv - decode an interrupt vector
242fb4d8502Sjsg *
243fb4d8502Sjsg * @adev: amdgpu_device pointer
244fb4d8502Sjsg *
245fb4d8502Sjsg * Decodes the interrupt vector at the current rptr
246fb4d8502Sjsg * position and also advance the position.
247fb4d8502Sjsg */
cik_ih_decode_iv(struct amdgpu_device * adev,struct amdgpu_ih_ring * ih,struct amdgpu_iv_entry * entry)248fb4d8502Sjsg static void cik_ih_decode_iv(struct amdgpu_device *adev,
249c349dbc7Sjsg struct amdgpu_ih_ring *ih,
250fb4d8502Sjsg struct amdgpu_iv_entry *entry)
251fb4d8502Sjsg {
252fb4d8502Sjsg /* wptr/rptr are in bytes! */
253c349dbc7Sjsg u32 ring_index = ih->rptr >> 2;
254fb4d8502Sjsg uint32_t dw[4];
255fb4d8502Sjsg
256c349dbc7Sjsg dw[0] = le32_to_cpu(ih->ring[ring_index + 0]);
257c349dbc7Sjsg dw[1] = le32_to_cpu(ih->ring[ring_index + 1]);
258c349dbc7Sjsg dw[2] = le32_to_cpu(ih->ring[ring_index + 2]);
259c349dbc7Sjsg dw[3] = le32_to_cpu(ih->ring[ring_index + 3]);
260fb4d8502Sjsg
261c349dbc7Sjsg entry->client_id = AMDGPU_IRQ_CLIENTID_LEGACY;
262fb4d8502Sjsg entry->src_id = dw[0] & 0xff;
263fb4d8502Sjsg entry->src_data[0] = dw[1] & 0xfffffff;
264fb4d8502Sjsg entry->ring_id = dw[2] & 0xff;
265fb4d8502Sjsg entry->vmid = (dw[2] >> 8) & 0xff;
266fb4d8502Sjsg entry->pasid = (dw[2] >> 16) & 0xffff;
267fb4d8502Sjsg
268fb4d8502Sjsg /* wptr/rptr are in bytes! */
269c349dbc7Sjsg ih->rptr += 16;
270fb4d8502Sjsg }
271fb4d8502Sjsg
272fb4d8502Sjsg /**
273fb4d8502Sjsg * cik_ih_set_rptr - set the IH ring buffer rptr
274fb4d8502Sjsg *
275fb4d8502Sjsg * @adev: amdgpu_device pointer
2765ca02815Sjsg * @ih: IH ring buffer to set wptr
277fb4d8502Sjsg *
278fb4d8502Sjsg * Set the IH ring buffer rptr.
279fb4d8502Sjsg */
cik_ih_set_rptr(struct amdgpu_device * adev,struct amdgpu_ih_ring * ih)280c349dbc7Sjsg static void cik_ih_set_rptr(struct amdgpu_device *adev,
281c349dbc7Sjsg struct amdgpu_ih_ring *ih)
282fb4d8502Sjsg {
283c349dbc7Sjsg WREG32(mmIH_RB_RPTR, ih->rptr);
284fb4d8502Sjsg }
285fb4d8502Sjsg
cik_ih_early_init(void * handle)286fb4d8502Sjsg static int cik_ih_early_init(void *handle)
287fb4d8502Sjsg {
288fb4d8502Sjsg struct amdgpu_device *adev = (struct amdgpu_device *)handle;
289fb4d8502Sjsg int ret;
290fb4d8502Sjsg
291fb4d8502Sjsg ret = amdgpu_irq_add_domain(adev);
292fb4d8502Sjsg if (ret)
293fb4d8502Sjsg return ret;
294fb4d8502Sjsg
295fb4d8502Sjsg cik_ih_set_interrupt_funcs(adev);
296fb4d8502Sjsg
297fb4d8502Sjsg return 0;
298fb4d8502Sjsg }
299fb4d8502Sjsg
cik_ih_sw_init(void * handle)300fb4d8502Sjsg static int cik_ih_sw_init(void *handle)
301fb4d8502Sjsg {
302fb4d8502Sjsg int r;
303fb4d8502Sjsg struct amdgpu_device *adev = (struct amdgpu_device *)handle;
304fb4d8502Sjsg
305c349dbc7Sjsg r = amdgpu_ih_ring_init(adev, &adev->irq.ih, 64 * 1024, false);
306fb4d8502Sjsg if (r)
307fb4d8502Sjsg return r;
308fb4d8502Sjsg
309fb4d8502Sjsg r = amdgpu_irq_init(adev);
310fb4d8502Sjsg
311fb4d8502Sjsg return r;
312fb4d8502Sjsg }
313fb4d8502Sjsg
cik_ih_sw_fini(void * handle)314fb4d8502Sjsg static int cik_ih_sw_fini(void *handle)
315fb4d8502Sjsg {
316fb4d8502Sjsg struct amdgpu_device *adev = (struct amdgpu_device *)handle;
317fb4d8502Sjsg
3185ca02815Sjsg amdgpu_irq_fini_sw(adev);
319fb4d8502Sjsg amdgpu_irq_remove_domain(adev);
320fb4d8502Sjsg
321fb4d8502Sjsg return 0;
322fb4d8502Sjsg }
323fb4d8502Sjsg
cik_ih_hw_init(void * handle)324fb4d8502Sjsg static int cik_ih_hw_init(void *handle)
325fb4d8502Sjsg {
326fb4d8502Sjsg struct amdgpu_device *adev = (struct amdgpu_device *)handle;
327fb4d8502Sjsg
328ad8b1aafSjsg return cik_ih_irq_init(adev);
329fb4d8502Sjsg }
330fb4d8502Sjsg
cik_ih_hw_fini(void * handle)331fb4d8502Sjsg static int cik_ih_hw_fini(void *handle)
332fb4d8502Sjsg {
333fb4d8502Sjsg struct amdgpu_device *adev = (struct amdgpu_device *)handle;
334fb4d8502Sjsg
335fb4d8502Sjsg cik_ih_irq_disable(adev);
336fb4d8502Sjsg
337fb4d8502Sjsg return 0;
338fb4d8502Sjsg }
339fb4d8502Sjsg
cik_ih_suspend(void * handle)340fb4d8502Sjsg static int cik_ih_suspend(void *handle)
341fb4d8502Sjsg {
342fb4d8502Sjsg struct amdgpu_device *adev = (struct amdgpu_device *)handle;
343fb4d8502Sjsg
344fb4d8502Sjsg return cik_ih_hw_fini(adev);
345fb4d8502Sjsg }
346fb4d8502Sjsg
cik_ih_resume(void * handle)347fb4d8502Sjsg static int cik_ih_resume(void *handle)
348fb4d8502Sjsg {
349fb4d8502Sjsg struct amdgpu_device *adev = (struct amdgpu_device *)handle;
350fb4d8502Sjsg
351fb4d8502Sjsg return cik_ih_hw_init(adev);
352fb4d8502Sjsg }
353fb4d8502Sjsg
cik_ih_is_idle(void * handle)354fb4d8502Sjsg static bool cik_ih_is_idle(void *handle)
355fb4d8502Sjsg {
356fb4d8502Sjsg struct amdgpu_device *adev = (struct amdgpu_device *)handle;
357fb4d8502Sjsg u32 tmp = RREG32(mmSRBM_STATUS);
358fb4d8502Sjsg
359fb4d8502Sjsg if (tmp & SRBM_STATUS__IH_BUSY_MASK)
360fb4d8502Sjsg return false;
361fb4d8502Sjsg
362fb4d8502Sjsg return true;
363fb4d8502Sjsg }
364fb4d8502Sjsg
cik_ih_wait_for_idle(void * handle)365fb4d8502Sjsg static int cik_ih_wait_for_idle(void *handle)
366fb4d8502Sjsg {
367fb4d8502Sjsg unsigned i;
368fb4d8502Sjsg u32 tmp;
369fb4d8502Sjsg struct amdgpu_device *adev = (struct amdgpu_device *)handle;
370fb4d8502Sjsg
371fb4d8502Sjsg for (i = 0; i < adev->usec_timeout; i++) {
372fb4d8502Sjsg /* read MC_STATUS */
373fb4d8502Sjsg tmp = RREG32(mmSRBM_STATUS) & SRBM_STATUS__IH_BUSY_MASK;
374fb4d8502Sjsg if (!tmp)
375fb4d8502Sjsg return 0;
376fb4d8502Sjsg udelay(1);
377fb4d8502Sjsg }
378fb4d8502Sjsg return -ETIMEDOUT;
379fb4d8502Sjsg }
380fb4d8502Sjsg
cik_ih_soft_reset(void * handle)381fb4d8502Sjsg static int cik_ih_soft_reset(void *handle)
382fb4d8502Sjsg {
383fb4d8502Sjsg struct amdgpu_device *adev = (struct amdgpu_device *)handle;
384fb4d8502Sjsg
385fb4d8502Sjsg u32 srbm_soft_reset = 0;
386fb4d8502Sjsg u32 tmp = RREG32(mmSRBM_STATUS);
387fb4d8502Sjsg
388fb4d8502Sjsg if (tmp & SRBM_STATUS__IH_BUSY_MASK)
389fb4d8502Sjsg srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_IH_MASK;
390fb4d8502Sjsg
391fb4d8502Sjsg if (srbm_soft_reset) {
392fb4d8502Sjsg tmp = RREG32(mmSRBM_SOFT_RESET);
393fb4d8502Sjsg tmp |= srbm_soft_reset;
394fb4d8502Sjsg dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
395fb4d8502Sjsg WREG32(mmSRBM_SOFT_RESET, tmp);
396fb4d8502Sjsg tmp = RREG32(mmSRBM_SOFT_RESET);
397fb4d8502Sjsg
398fb4d8502Sjsg udelay(50);
399fb4d8502Sjsg
400fb4d8502Sjsg tmp &= ~srbm_soft_reset;
401fb4d8502Sjsg WREG32(mmSRBM_SOFT_RESET, tmp);
402fb4d8502Sjsg tmp = RREG32(mmSRBM_SOFT_RESET);
403fb4d8502Sjsg
404fb4d8502Sjsg /* Wait a little for things to settle down */
405fb4d8502Sjsg udelay(50);
406fb4d8502Sjsg }
407fb4d8502Sjsg
408fb4d8502Sjsg return 0;
409fb4d8502Sjsg }
410fb4d8502Sjsg
cik_ih_set_clockgating_state(void * handle,enum amd_clockgating_state state)411fb4d8502Sjsg static int cik_ih_set_clockgating_state(void *handle,
412fb4d8502Sjsg enum amd_clockgating_state state)
413fb4d8502Sjsg {
414fb4d8502Sjsg return 0;
415fb4d8502Sjsg }
416fb4d8502Sjsg
cik_ih_set_powergating_state(void * handle,enum amd_powergating_state state)417fb4d8502Sjsg static int cik_ih_set_powergating_state(void *handle,
418fb4d8502Sjsg enum amd_powergating_state state)
419fb4d8502Sjsg {
420fb4d8502Sjsg return 0;
421fb4d8502Sjsg }
422fb4d8502Sjsg
423fb4d8502Sjsg static const struct amd_ip_funcs cik_ih_ip_funcs = {
424fb4d8502Sjsg .name = "cik_ih",
425fb4d8502Sjsg .early_init = cik_ih_early_init,
426fb4d8502Sjsg .late_init = NULL,
427fb4d8502Sjsg .sw_init = cik_ih_sw_init,
428fb4d8502Sjsg .sw_fini = cik_ih_sw_fini,
429fb4d8502Sjsg .hw_init = cik_ih_hw_init,
430fb4d8502Sjsg .hw_fini = cik_ih_hw_fini,
431fb4d8502Sjsg .suspend = cik_ih_suspend,
432fb4d8502Sjsg .resume = cik_ih_resume,
433fb4d8502Sjsg .is_idle = cik_ih_is_idle,
434fb4d8502Sjsg .wait_for_idle = cik_ih_wait_for_idle,
435fb4d8502Sjsg .soft_reset = cik_ih_soft_reset,
436fb4d8502Sjsg .set_clockgating_state = cik_ih_set_clockgating_state,
437fb4d8502Sjsg .set_powergating_state = cik_ih_set_powergating_state,
438fb4d8502Sjsg };
439fb4d8502Sjsg
440fb4d8502Sjsg static const struct amdgpu_ih_funcs cik_ih_funcs = {
441fb4d8502Sjsg .get_wptr = cik_ih_get_wptr,
442fb4d8502Sjsg .decode_iv = cik_ih_decode_iv,
443fb4d8502Sjsg .set_rptr = cik_ih_set_rptr
444fb4d8502Sjsg };
445fb4d8502Sjsg
cik_ih_set_interrupt_funcs(struct amdgpu_device * adev)446fb4d8502Sjsg static void cik_ih_set_interrupt_funcs(struct amdgpu_device *adev)
447fb4d8502Sjsg {
448fb4d8502Sjsg adev->irq.ih_funcs = &cik_ih_funcs;
449fb4d8502Sjsg }
450fb4d8502Sjsg
451f005ef32Sjsg const struct amdgpu_ip_block_version cik_ih_ip_block = {
452fb4d8502Sjsg .type = AMD_IP_BLOCK_TYPE_IH,
453fb4d8502Sjsg .major = 2,
454fb4d8502Sjsg .minor = 0,
455fb4d8502Sjsg .rev = 0,
456fb4d8502Sjsg .funcs = &cik_ih_ip_funcs,
457fb4d8502Sjsg };
458